I was looking for a way to remove the TinyMCE Editor for a specific page template in a theme (in my case it’s page-home.php). I found the following code, which works, however, I was wondering if this could be accomplished in a better/neater way, perhaps using some of WordPress’ built-in functions for finding the ID of the page…
function hide_editor() {
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
if( !isset( $post_id ) ) return;
$template_file = get_post_meta($post_id, '_wp_page_template', true);
if($template_file == 'page-home.php'){ // template name here
remove_post_type_support('page', 'editor');
}
}
add_action( 'admin_init', 'hide_editor' );
You can try to hook on
load-page
hook instead ofadmin_init
. It is supposed to be called only when a page is being edited, and then you should be able to use the global$post
variableThis worked for me: