Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active September 24, 2016 23:36
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/1321431 to your computer and use it in GitHub Desktop.
Save billerickson/1321431 to your computer and use it in GitHub Desktop.
Hide Editor on Specific Template Page
<?php
/**
* Hide Editor
* @author Bill Erickson
* @link http://www.billerickson.net/code/hide-editor-on-specific-page-template/
*/
function be_hide_editor() {
// Get the Post ID
$post_id = false;
if( isset( $_GET['post'] ) )
$post_id = $_GET['post'];
elseif( isset( $_POST['post_ID'] ) )
$post_id = $_POST['post_ID'];
$post_id = intval( $post_id );
if( ! $post_id )
return;
$current_template = get_page_template_slug( $post_id );
$exclude_on = array( 'group-classes.php', 'trainers.php' );
if( in_array( $current_template, $exclude_on ) )
wp_enqueue_style( 'hide-editor', get_stylesheet_directory_uri() . '/css/hide-editor.css' );
}
add_action( 'admin_enqueue_scripts', 'be_hide_editor' );
#postdivrich{display: none;}
@halfempty
Copy link

Thanks!

@ataylorme
Copy link

@billerickson I think this can be improved. Instead of using wp_enqueue_style and css to hide the editor you can use
remove_post_type_support. You'll just have to change the action from admin_enqueue_scripts to admin_init.

function be_hide_editor() {
        // Get the Post ID
        if( isset( $_GET['post'] ) ) $post_id = $_GET['post'];
        elseif( isset( $_POST['post_ID'] ) ) $post_id = $_POST['post_ID'];
        if( !isset( $post_id ) ) return;

        // Get the Page Template
        $template_file = get_post_meta( $post_id, '_wp_page_template', true );

        // Exclude on these templates
        $exclude_templates = array( 'template-branch.php' );

        // Exclude on these IDs
        $exclude_ids = array( get_option( 'page_on_front' ) );

        if( in_array( $template_file, $exclude_templates ) || in_array( $post_id, $exclude_ids ) )
                remove_post_type_support('page', 'editor');
}//be_hide_editor
add_action( 'admin_init', 'be_hide_editor' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment