最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - Hide tag and category boxes from the post editor

programmeradmin6浏览0评论

I want to hide the tag and category boxes from the post editor, the theme I've just developed doesn't need them, thus I want to hide them.

I am aware they could be hidden using the 'screen options' menu, however I'd prefer to do this with a bit of code.

Is this possible?

I want to hide the tag and category boxes from the post editor, the theme I've just developed doesn't need them, thus I want to hide them.

I am aware they could be hidden using the 'screen options' menu, however I'd prefer to do this with a bit of code.

Is this possible?

Share Improve this question asked Aug 2, 2012 at 9:16 Ben EverardBen Everard 1,2885 gold badges19 silver badges34 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 6

Using remove metabox function you can do this. Simply put this inside your themes functions.php file at very end.

NOTE - unwrap <?php ?> if necessary.

<?php 
function wpse60590_remove_metaboxes() {
    remove_meta_box( 'categorydiv' , 'post' , 'normal' ); 
    remove_meta_box( 'tagsdiv-post_tag' , 'post' , 'normal' ); 

}
add_action( 'admin_menu' , 'wpse60590_remove_metaboxes' );
?>

As @marks-polakovs commented above, this approach doesn't seem to work w/ Gutenberg, and it took me some time to find the following, which does work:

//* Remove default Categories metabox from sidebar in Gutenberg editor
add_action( 'enqueue_block_editor_assets', 'remove_category_panel' );
function remove_category_panel() {
  wp_add_inline_script( 'wp-embed', "
    wp.data.dispatch( 'core/edit-post' ).removeEditorPanel( 'taxonomy-panel-category' );
" );
}
发布评论

评论列表(0)

  1. 暂无评论