如何隐藏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’);
}
}

相关推荐

发表回复

房先生
我们将24小时内回复。
2024-05-10 12:58:19
您好,有任何疑问请与我们联系!
您的工单我们已经收到,我们将会尽快跟您联系!
[QQ客服]
2781198
加我微信
[电话联系]
13585372227
[电子邮件]
chaoneo@163.com
取消

选择聊天工具: