1

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' );
  • I haven't tested the code but that looks fine to me. – s_ha_dum Feb 10 '13 at 20:12
1

You can try to hook on load-page hook instead of admin_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 variable

function hide_editor() {
   global $post;

    $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( 'load-page', 'hide_editor' );
  • I finally got the time to test out your code. It doesn't seem to work unfortunately... – Ian Muscat Feb 22 '13 at 21:18
0

This worked for me:

function hide_editor() {
  if(isset($_REQUEST['post'])){
    $post_id = $_REQUEST['post'];
    $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( 'load-post.php', 'hide_editor' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.