Skip to content

Instantly share code, notes, and snippets.

@ramseyp
Created November 12, 2012 15:48
Show Gist options
  • Star 67 You must be signed in to star a gist
  • Fork 19 You must be signed in to fork a gist
  • Save ramseyp/4060095 to your computer and use it in GitHub Desktop.
Save ramseyp/4060095 to your computer and use it in GitHub Desktop.
Hide the content editor for certain pages in WordPress
<?php
/**
* Hide editor on specific pages.
*
*/
add_action( 'admin_init', 'hide_editor' );
function hide_editor() {
// Get the Post ID.
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
if( !isset( $post_id ) ) return;
// Hide the editor on the page titled 'Homepage'
$homepgname = get_the_title($post_id);
if($homepgname == 'Homepage'){
remove_post_type_support('page', 'editor');
}
// Hide the editor on a page with a specific page template
// Get the name of the Page Template file.
$template_file = get_post_meta($post_id, '_wp_page_template', true);
if($template_file == 'my-page-template.php'){ // the filename of the page template
remove_post_type_support('page', 'editor');
}
}
@praghavaji
Copy link

Thanks. Very awesome.

@olirabt
Copy link

olirabt commented Sep 23, 2016

Hello, thanks, this works perfectly. However, I was unable to disable the editor also on the translated pages in my admin. I use polylang plugin in order to translate my pages. The editor is disabled on the original page, but it is abled on the pages I use for traductions.
Could you please help me in hiding the editor on all pages ?
Thanks

@cramdesign
Copy link

possibly a cleaner way still to get the name of the template file:

$template_file = basename( get_page_template() );

@RyuuZaky
Copy link

Thanks bro, really useful 👍

@endymion1818
Copy link

Thanks to both of you, really helped me too.

@jordanboston
Copy link

jordanboston commented May 26, 2017

Thanks! This seemed to work well for me, from the combined comments above:

add_action( 'admin_head', 'hide_editor' );
function hide_editor() {
	$template_file = $template_file = basename( get_page_template() );
	if($template_file == 'template.php'){ // template
		remove_post_type_support('page', 'editor');
	}
}

It seems simpler, and I have not seen any issues.

@anthonyhartnell
Copy link

@jordanboston you have written $template file twice on line 3:

$template_file = $template_file = basename( get_page_template() );

@bluefractals
Copy link

Is there a way to move it below other fields on the page? I'm using Advanced Custom Fields and would like to move the default content area below the ACF fields.

@billyranario
Copy link

Very helpful!

@roborracle
Copy link

@jordanboston - that worked perfectly - thank you.

Copy link

ghost commented Jun 18, 2018

Thanks to @ramseyp, @jordanboston and @WebAssembler - works great.

@edurodriguesdias
Copy link

Thanks bro!

@ncole458
Copy link

ncole458 commented Sep 11, 2018

Nice one thanks! I needed to add remove_post_type_support('post', 'editor'); to remove from posts also FYI.

@MikeNGarrett
Copy link

Make sure you check to see if you're on the right admin screen by using get_current_screen().

@anthonyabraira
Copy link

What if the template files are in a folder like:

page-sections/page-hero-banner.php

I tried this to no avail:

/**
 * Hide editor on specific pages.
 *
 */
add_action( 'admin_init', 'hide_editor' );
function hide_editor() {
  // Get the Post ID.
  $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
  if( !isset( $post_id ) ) return;

  // Hide the editor on a page with a specific page template
  // Get the name of the Page Template file.
  $template_file = get_post_meta($post_id, '_wp_page_template', true);

  
  if($template_file == 'page-section/page-event-feature.php'){ // the filename of the page template
    remove_post_type_support('page', 'editor');
  }
}

@emmadalby
Copy link

Very helpful. Thanks so much!

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