Posted By

f6design on 12/01/11


Tagged

wordpress editor wysiwyg


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

Kurt
chrisdemetriad
rickygri
rickahontas
fhenderson


Wordpress: Disable the content editor for a specific page template


 / Published in: PHP
 

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.

  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
Posted By: rickahontas on February 18, 2013

Thanks, works great.

You need to login to post a comment.