我正在尝试从WordPress后台中删除自定义字段部分。我认为我找到了一个显示自定义字段的函数。该函数位于wp-admin/edit-page-form.php第181行。
do_meta_boxes('page','normal',$post)
当我移除这个函数时,WordPress也不会显示其他的框。
我如何从WordPress后台移除特定的框?
我正在尝试从WordPress后台中删除自定义字段部分。我认为我找到了一个显示自定义字段的函数。该函数位于wp-admin/edit-page-form.php第181行。
do_meta_boxes('page','normal',$post)
当我移除这个函数时,WordPress也不会显示其他的框。
我如何从WordPress后台移除特定的框?
function remove_metaboxes() {
remove_meta_box( 'postcustom' , 'page' , 'normal' ); //removes custom fields for page
remove_meta_box( 'commentstatusdiv' , 'page' , 'normal' ); //removes comments status for page
remove_meta_box( 'commentsdiv' , 'page' , 'normal' ); //removes comments for page
remove_meta_box( 'authordiv' , 'page' , 'normal' ); //removes author for page
}
add_action( 'admin_menu' , 'remove_metaboxes' );
将"page"改为"post"即可对帖子执行此操作
将此代码放入您的function.php文件中
add_action( 'do_meta_boxes', 'remove_default_custom_fields_meta_box', 1, 3 );
function remove_default_custom_fields_meta_box( $post_type, $context, $post ) {
remove_meta_box( 'postcustom', $post_type, $context );
}
您可以通过编辑管理界面中每个框的CSS来最轻松地完成此操作。首先想到的方法是将以下内容添加到您主题的functions.php文件中。
<?php
add_action('wp_head','hide_custom_fields_postbox');
function hide_custom_fields_postbox()
{
if ( is_admin() ) {
?>
<style type="text/css">
div#postcustom {display:none;}
</style>
<?php
}
}//end function
?>