WordPress教程

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

阿里云

当我们添加一些元数据到 WordPress 中的某个页面的时候,WordPress 默认的编辑器可能就用不上了。为了提高用户的编辑体验,把这些页面的可视化编辑器隐藏掉是一个比较直接的办法。

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

也想出现在这里?联系我们
创客主机
  1. noediter。
  2. add_action( 'admin_init', 'hide_editor' );
  3.  
  4. function hide_editor() {
  5. 	// Get the Post ID.
  6. 	$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
  7. 	if( !isset( $post_id ) ) return;
  8.  
  9. 	// Get the name of the Page Template file.
  10. 	$template_file = get_post_meta($post_id, '_wp_page_template', true);
  11.  
  12.     if($template_file == 'contact.php'){ // edit the template name
  13.     	remove_post_type_support('page', 'editor');
  14.     }
  15. }

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

已有 115 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!