百度 | 神马 | 搜狗 | 技术文档 | 学习资料分享 - 记录帝国CMS及运维技术的点点滴滴
你的位置:首页 > 实用IT技术 » 正文

【Wordpress相关】WordPress 技巧:移除特定页面模板下的内容编辑器

发布时间:2020-09-17

作品分类:Wordpress相关  页面  只需  模板  编辑器  移除  特定  模板  页面

WordPress 技巧:移除特定页面模板下的内容编辑器,

有时候一些特殊模板页面(比如联系我们页面)编辑后台,你可能添加了一些表单之后,想移除默认的编辑器,只需要在当前主题的 functions.php 文件添加下面的代码:

add_action( 'admin_init', 'wpjam_remove_editor' );
function wpjam_remove_editor() {
	$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
	if( !isset( $post_id ) ) return;

	$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');
	}
}

只需要把上面的 contact.php 替换成你的页面模板即可。

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>


本站推荐使用的主机:,国外主机建议使用

Top