Hide page visual editor if template is selected – redux

The following works for me, testing with TwentyTwelve.

Using load-{$pagenow} instead of admin_init avoids the checking for the global $pagenow. See comments for further info:

// Run only when editing a page
// For new pages load-page-new.php should be used
// See: http://core.trac.wordpress.org/browser/tags/3.5.1/wp-admin/admin.php#L217
add_action( 'load-page.php', 'hide_editor_wpse_88886' );

function hide_editor_wpse_88886() 
{
    // Not really necessary, but just in case
    if( !isset( $_GET['post'] ) )
        return;

    $template = get_post_meta( $_GET['post'] , '_wp_page_template', true );

    if( 'page-templates/front-page.php' == $template )
    {
        remove_post_type_support( 'page', 'editor' );
    }
}

Leave a Comment