Skip to content

Instantly share code, notes, and snippets.

@blainerobison
Created July 6, 2015 17:12
Show Gist options
  • Save blainerobison/dca045adf1f0d76d519d to your computer and use it in GitHub Desktop.
Save blainerobison/dca045adf1f0d76d519d to your computer and use it in GitHub Desktop.
WordPress Hide Editor
<?php
/**
* Hide Editor
*/
function prefix_hide_editor() {
// get post id
if ( isset( $_GET['post'] ) ) :
$post_id = $_GET['post'];
elseif ( isset( $_POST['post_ID'] ) ) :
$post_id = $_POST['post_ID'];
endif;
// bail since we have no post id
if ( ! isset( $post_id ) ) return;
// get page template
$template_file = get_post_meta( $post_id, '_wp_page_template', true );
// exclude page templates
$exclude_templates = array(
'tpl-templatename.php'
);
// exclude ids
$exclude_ids = array( get_option( 'page_on_front' ) );
// exclude custom post types
$current_screen = get_current_screen();
$screen_id = $current_screen->post_type;
$post_types = array(
'post_type'
);
if ( in_array( $template_file, $exclude_templates ) ||
in_array( $post_id, $exclude_ids ) ||
in_array( $screen_id, $post_types ) ) :
?>
<style type="text/css">
#postdivrich{ display: none; }
</style>
<?php
endif;
}
add_action( 'admin_head', 'prefix_hide_editor' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment