Home / admin / Disable content editor for specific page template
  • How to Disable content editor for specific page template


    Adding this snippet to the functions.php of your wordpress theme will disable the content editor when a page is using a specific template. Don’t forget to change the name of the template file on line 08 this sample I have submit.php but can be changed to anything.

    ( click code to copy )

    wordpress snippet : PHP

    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');

    ( WordPress codex functions, hooks, in this snippet. )

    template, page_template, init, get_post, remove_post_type_support, get_post_meta, add_action, _e, wp,
  • Thanks for this. I’ll have to try it!

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

  • Robert

    gracias, muy util

  • Chris

    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!

  • Tks

  • Sampath

    Thank you. It worked for me.

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