禁用特定页面模板的内容编辑器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了禁用特定页面模板的内容编辑器相关的知识,希望对你有一定的参考价值。

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. }

以上是关于禁用特定页面模板的内容编辑器的主要内容,如果未能解决你的问题,请参考以下文章