Last active
November 30, 2017 00:14
-
-
Save sirchrispy/8d7c44670e0d0e4010df54ebe04aeae8 to your computer and use it in GitHub Desktop.
Remove the Content Editor in WordPress and Genesis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'do_meta_boxes', 'tcd_remove_content_editor' ); | |
/** | |
* Remove content editor on some pages | |
* | |
* This is particularly useful for page templates and front pages. We hook into | |
* 'do_meta_boxes' because it manipulates already-registered meta boxes, firing | |
* after the 'add_meta_boxes' hook, but before the meta boxes are echoed. | |
* | |
* @author Chris Mower | |
* @link https://gist.github.com/chrismower/8d7c44670e0d0e4010df54ebe04aeae8 | |
*/ | |
function tcd_remove_content_editor() { | |
// If not on a page edit screen, stop | |
$screen = get_current_screen(); | |
if( !($screen->post_type == 'page' ) ) { | |
return; | |
} | |
// Remove content editor using page title | |
$page = get_the_title(); // get the page title | |
$pages = ['Home', 'Blog', 'Calendar']; // define the affected page titles | |
if( in_array( $page, $pages, TRUE ) ) { // compare our page titles with existing titles | |
remove_post_type_support( 'page', 'editor' ); // remove the content editor | |
} | |
// Remove content editor using page slug | |
$slug = get_post_field( 'post_name', get_post() ); // get the slug | |
$slugs = ['recipe-search', 'search-results']; // define the affected slugs | |
if( in_array( $slug, $slugs, TRUE ) ) { // check if specified slugs exist using an exact match | |
remove_post_type_support( 'page', 'editor' ); // remove the content editor | |
} | |
// Remove content editor using page template | |
$template = basename( get_page_template() ); // get the page templates | |
$templates = ['front-page.php', 'page_archive.php', 'page_blog.php']; // define affected templates | |
if( in_array( $template, $templates, TRUE ) ) { // check if our templates match registered templates | |
remove_post_type_support( 'page', 'editor' ); // if matched, remove content editor | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment