Wordpress: Disable the content editor for a specific page template


/ Published in: PHP
Save to your folder(s)

When adding a meta box to a 'page' in Wordpress (as opposed to a post, or custom post type), you might want to disable the default editor. Use this snippet in your theme's functions.php file to disable the editor for a specific page template.


Copy this code and paste it in your HTML
  1. /**
  2.  * Hide editor for specific page templates.
  3.  *
  4.  */
  5. add_action( 'admin_init', 'hide_editor' );
  6.  
  7. function hide_editor() {
  8. // Get the Post ID.
  9. $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
  10. if( !isset( $post_id ) ) return;
  11.  
  12. // Get the name of the Page Template file.
  13. $template_file = get_post_meta($post_id, '_wp_page_template', true);
  14.  
  15. if($template_file == 'contact.php'){ // edit the template name
  16. remove_post_type_support('page', 'editor');
  17. }
  18. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.