隐藏指定页面模板的可视化编辑器

页面功能中有很多时候可能是需要隐藏掉页面编辑器的,便于在某些特定的开发中,可以有空间设置更多自定义选项。这个时候WordPress默认的编辑器可能就用不上了。为了提高用户的编辑体验,把这些页面的可视化编辑器隐藏掉是一个比较直接的办法。

使用方法:

直接把下面的代码复制到主题的 functions.php 中就可以了。复制之前,需要先替换下面代码中的 contact.php 为你所用主题的页面模板名称。比如,我在主题中定义了一个模板叫 page-abouts.php,就需要把 contact.php 替换为 page-abouts.php即可。

  1. add_action( 'admin_init', 'hide_editor' );
  2. function hide_editor() {
  3. 	// Get the Post ID.
  4. 	$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
  5. 	if( !isset( $post_id ) ) return;
  6.  
  7. 	// Get the name of the Page Template file.
  8. 	$template_file = get_post_meta($post_id, '_wp_page_template', true);
  9.  
  10.     if($template_file == 'contact.php'){ // edit the template name
  11.     	remove_post_type_support('page', 'editor');
  12.     }
  13. }
话题:

相关推荐