Disable Content Editor for Specific Page Template

Snippets by IsItWP

Sometimes you don’t need a content editor for the specific page templates. It’s useful for thank you pages and other pages that has a fixed text and may not need any content.

Instructions: Add the following code to the functions.php file of your WordPress theme.
You need to change the template filename in the code. Currently it’s submit.php but you can replace it with any filename.

add_action( 'admin_init', 'hide_editor' );

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 == 'submit.php'){ // edit the template name
    	remove_post_type_support('page', 'editor');

You may also enjoy adding custom CSS for WordPress editor.

Comments   Leave a Reply

  1. its not working for me 🙁

    1. If the template is in a folder, you may have to use this pattern: if($template_file == ‘templates/template-example.php’){ // edit the template name and folder name to match the correct path

      Also, be sure to refresh the page in the browser.

  2. Why not use:


    instead of:

    $post_id = $_GET[‘post’] ? $_GET[‘post’] : $_POST[‘post_ID’] ;

    1. get_the_ID(); needs to be inside the WordPress Loop, whereas this snippet needs to work in the admin.

  3. Edvins Antonovs January 8, 2015 at 8:40 am

    It worked for me! Great stuff.
    Added it to my snippet collection.

  4. Thank you. It worked for me.

  5. Marcos Nakamine May 15, 2014 at 1:33 pm


  6. You just saved me, my friend. Thanks a million!

    Just FYI, my admin page initially didn’t load on a server error after putting in the code above. I changed this:

    $post_id = $_GET[‘post’] ? $_GET[‘post’] : $_POST[‘post_ID’] ;
    if( !isset( $post_id ) ) return;

    to this:

    if ( isset ( $_GET[‘post’] ) )
    $post_id = $_GET[‘post’];
    else if ( isset ( $_POST[‘post_ID’] ) )
    $post_id = $_POST[‘post_ID’];

    if( !isset ( $post_id ) || empty ( $post_id ) )

    …and it fixed the issue.

    Thanks again!

  7. gracias, muy util

  8. this doesn’t work for me, I get the errors undefined index post and post_ID in the backend

  9. Thanks for this. I’ll have to try it!

    1.  Cool glad you like it.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!