国内外主机
测评及优惠码

如何隐藏WordPress指定页面模板的可视化编辑器呢?

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

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

add_action( 'admin_init', 'hide_editor' );    function hide_editor() {  	// Get the Post ID.  	$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;  	if( !isset( $post_id ) ) return;    	// Get the name of the Page Template file.  	$template_file = get_post_meta($post_id, '_wp_page_template', true);            if($template_file == 'contact.php'){ // edit the template name      	remove_post_type_support('page', 'editor');      }  }

 

赞一个
赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《如何隐藏WordPress指定页面模板的可视化编辑器呢?》
文章链接:https://www.ibytx.com/1967.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

登录

找回密码

注册