Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 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' );
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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