Created
November 12, 2012 15:48
-
-
Save ramseyp/4060095 to your computer and use it in GitHub Desktop.
Hide the content editor for certain pages in WordPress
This file contains hidden or 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 | |
/** | |
* Hide editor on specific pages. | |
* | |
*/ | |
add_action( 'admin_init', 'hide_editor' ); | |
function hide_editor() { | |
// Get the Post ID. | |
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ; | |
if( !isset( $post_id ) ) return; | |
// Hide the editor on the page titled 'Homepage' | |
$homepgname = get_the_title($post_id); | |
if($homepgname == 'Homepage'){ | |
remove_post_type_support('page', 'editor'); | |
} | |
// Hide the editor on a page with a specific page template | |
// Get the name of the Page Template file. | |
$template_file = get_post_meta($post_id, '_wp_page_template', true); | |
if($template_file == 'my-page-template.php'){ // the filename of the page template | |
remove_post_type_support('page', 'editor'); | |
} | |
} |
Thanks bro!
Nice one thanks! I needed to add remove_post_type_support('post', 'editor');
to remove from posts also FYI.
Make sure you check to see if you're on the right admin screen by using get_current_screen()
.
What if the template files are in a folder like:
page-sections/page-hero-banner.php
I tried this to no avail:
/**
* Hide editor on specific pages.
*
*/
add_action( 'admin_init', 'hide_editor' );
function hide_editor() {
// Get the Post ID.
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
if( !isset( $post_id ) ) return;
// Hide the editor on a page with a specific page template
// Get the name of the Page Template file.
$template_file = get_post_meta($post_id, '_wp_page_template', true);
if($template_file == 'page-section/page-event-feature.php'){ // the filename of the page template
remove_post_type_support('page', 'editor');
}
}
Very helpful. Thanks so much!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to @ramseyp, @jordanboston and @WebAssembler - works great.