Skip to content

Instantly share code, notes, and snippets.

@atomtigerzoo
Forked from ramseyp/hide-editor.php
Last active December 29, 2020 17:25
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save atomtigerzoo/0dd49ed9ca67ec111465 to your computer and use it in GitHub Desktop.
Save atomtigerzoo/0dd49ed9ca67ec111465 to your computer and use it in GitHub Desktop.
Wordpress: Hide the editor on defined pages
/**
* Hide the main editor on specific pages
*/
define('EDITOR_HIDE_PAGE_TITLES', json_encode(array()));
define('EDITOR_HIDE_PAGE_TEMPLATES', json_encode(array('template-cars.php')));
/**
* Hide the main editor on defined pages
*
* You can choose between page titles or page templates. Just set them
* accordingly like this:
*
* define('EDITOR_HIDE_PAGE_TITLES', json_encode(array('Home', 'Some post archive', 'Some Listing')));
* define('EDITOR_HIDE_PAGE_TEMPLATES', json_encode(array('template-of-something.php', 'archive-customposttype.php')));
*
*
* @global string $pagenow
* @return void
*/
function atz_hide_editor() {
global $pagenow;
if(!('post.php' == $pagenow)){
return;
}
// Get the Post ID.
$post_id = filter_input(INPUT_GET, 'post') ? filter_input(INPUT_GET, 'post') : filter_input(INPUT_POST, 'post_ID');
if(!isset($post_id)) {
return;
}
// Hide the editor on the page titled 'Homepage'
if(in_array(get_the_title($post_id), json_decode(EDITOR_HIDE_PAGE_TITLES))) {
remove_post_type_support('page', 'editor');
}
// Hide the editor on a page with a specific page template
$template_filename = get_post_meta($post_id, '_wp_page_template', true);
if(in_array($template_filename, json_decode(EDITOR_HIDE_PAGE_TEMPLATES))) {
remove_post_type_support('page', 'editor');
}
}
add_action('admin_init', 'atz_hide_editor');
@Hollyw00d
Copy link

Thank you! Worked perfectly for hiding the editor on specific pages and/or templates.

@Pixelworlds
Copy link

To add support for hiding by post type

define('EDITOR_HIDE_POST_TYPES', json_encode(array('page')));
if(in_array(get_post_type($post_id), json_decode(EDITOR_HIDE_POST_TYPES))) {
	remove_post_type_support('page', 'editor');
}

@aaronsummers
Copy link

Thank you

@jsmeltzer
Copy link

👍

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