预计阅读时间: 2 分钟

有时候一些特殊模板页面(比如联系我们页面)编辑后台,你可能添加了一些表单之后,想移除默认的编辑器,只需要在当前主题的 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 替换成你的页面模板即可。

此文章对你有帮助吗? 已有 0 人说这篇文章是有用的。