20

I have two hierarchical custom taxonomies, each on a corresponding custom post type. I would like to remove the metabox for each on the post type's edit screen.

I have read remove custom taxonomy metabox form custom post type and How do you remove a Category-style (hierarchical) taxonomy metabox? but I'm still stuck.

The function I'm using is:

function remove_taxonomies_metaboxes() {
    remove_meta_box( 'partner_typediv', 'partners', 'normal' );
    remove_meta_box( 'person_typediv', 'people', 'normal' );
}
add_action( 'admin_menu' , 'remove_taxonomies_metaboxes' );

I unprefixed the post_types and custom_taxonomies, but that's it. I've tried using the admin_menu hook and the add_meta_boxes hook recommended by the Codex. I've tried both normal and side for the third parameter.

The above function is located in an mu-plugins file below the function that registers the post types and taxonomies.


EDIT: It was a typo in the register_taxonomy function. I'm a horrible person. Thanks for everyone for the help. I still learned some stuff!

2
  • 1
    even with 'show_ui' => false?
    – JMau
    Jun 11, 2013 at 18:59
  • 1
    I want the UI in the menu still, just not when editing a post.
    – mrwweb
    Jun 11, 2013 at 21:23

4 Answers 4

58

If you are manually registering your custom taxonomy via register_taxonomy then you can pass in arguments to control where the metabox appears.

In the example below setting show_ui to false would completely remove the metabox from the edit screen, the quick edit screen, and the admin menu. But if you set show_ui to true you can achieve more nuanced control by then using the show_in_quick_edit and meta_box_cb arguments (setting the later to false hides the metabox on the CPT edit screen as desired).

register_taxonomy( 'your_custom_taxonomy', array( 'your_custom_post_type' ), $args );
$args = array(
    'show_ui'                    => true,
    'show_in_quick_edit'         => false,
    'meta_box_cb'                => false,
);
3
  • It work. keep admin menu and remove custom taxonomy in form add new of custom post type. Thanks.
    – IT Vlogs
    Jun 10, 2016 at 10:01
  • Thank you! I was looking for 'meta_box_cb'=>false to hide it in post-new, where setting it to null just displays the default wordpress version.
    – Ryan H
    Apr 1, 2017 at 13:15
  • Smooth and simple. Sep 6, 2018 at 9:45
7

You say you want to remove the boxes from the post edit screen, not the Post type screen, so assuming that you should be able to register your taxonomy only for the post types you want it to apply to, and avoid this altogether. The example in the Codex registers the sample taxonomy only for the book post type like:

register_taxonomy( 'genre', array( 'book' ), $args );

I think this is what you need to do, but you did not post any registration code for the post types or the taxonomies.

If you have created the meta boxes yourself-- that is, these boxes are not the default ones-- then the way to avoid this issue is to register the meta boxes on the post-type specific hooks:

do_action('add_meta_boxes_' . $post_type, $post);

Or to follow the example above:

add_action('add_meta_boxes_book', 'your-box-callback');

One of those approaches should solve this for you. I don't think you should have to use remove_meta_box at all.

If you are trying to remove the meta boxes from the post type that they are registered to, this works (again following the example in the Codex):

function remove_taxonomies_metaboxes() {
    remove_meta_box( 'genrediv', 'book', 'side' );
}
add_action( 'add_meta_boxes_book' , 'remove_taxonomies_metaboxes' );

I am pretty sure that admin_menu is too early, but didn't verify that. add_metaboxes also works for me. I don't know why it does not work for you.

5
  • Sorry for being unclear. I meant the Post Type screen. Each taxonomy is only registered to one custom post type. I tried use that add_meta_boxes_* hook briefly but I'll go try some variations on that (though I'm using the auto-generated metaboxes).
    – mrwweb
    Jun 11, 2013 at 21:25
  • Then the last option in the answer should do it. I tested it. The box does go away. I can't say I understand the logic of having the taxonomies without the boxes though.
    – s_ha_dum
    Jun 11, 2013 at 21:28
  • (See edit above. It was a typo. That's on me... Thanks for the help). To answer your question, I'm displaying the taxonomies with an Advanced Custom Field (it's a better interface for the users of the site).
    – mrwweb
    Jun 11, 2013 at 21:34
  • Your last example did put me in the right direction, but this is what worked for me: add_action( 'admin_menu', 'remove_taxonomies_metaboxes' ); Dec 12, 2017 at 17:12
  • I found this syntax doesn't work with the current version of WordPress, check this answer for a working solution.
    – Davey
    May 2, 2018 at 9:06
4

Taxonomies register a meta_box by default using a tagsdiv-xxx id. Using ACF for the custom taxonomies management, the default metaboxes are unnecessary. I've tried, successfully, this code:

      function remove_cuttax_metaboxes() {
           $post_type = 'post';
           $taxonomy = 'custom_taxonomy_slug';
           remove_meta_box( 'tagsdiv-'.$taxonomy, $post_type, 'side' );

       }
       add_action( 'admin_menu' , 'remove_cuttax_metaboxes', 100 );

The lower priority (100) let this code work also if the taxonomies are created by a plugin like CPT-UI.

3
  • 1
    tagsdiv should have trailing -: remove_meta_box( 'tagsdiv-'.$taxonomy, $post_type, 'side' ); Aug 2, 2019 at 1:33
  • This doesn't work any more in Gutenberg.
    – Sudar
    Nov 19, 2020 at 8:13
  • As of WordPress 5.6, 'tagsdiv-' is no longer valid. Use the following combination to create the corresponding id: remove_meta_box( $taxonomy . 'div', $post_type, 'side' );
    – Talha Imam
    Feb 23, 2021 at 14:05
0

I tried the above solutions to hide the taxonomy but it didn't work for me. Finally, I found a solution.

Add this code in your theme's functions.php file.

function Cc_Gutenberg_Register_files() 
{
    //custom script file
    wp_register_script(
        'cc-block-script',
        get_stylesheet_directory_uri() .'/js/block-script.js',
        array( 'wp-blocks', 'wp-edit-post' )
    );
    // register block editor script
    register_block_type( 'cc/ma-block-files', array(
        'editor_script' => 'cc-block-script'
    ) );     
}
add_action('init', 'Cc_Gutenberg_Register_files');

For block-script.js, you can use this code.

wp.data.dispatch( 'core/edit-post').removeEditorPanel( 'taxonomy-panel-category' ) ; // Hide default Category
wp.data.dispatch( 'core/edit-post').removeEditorPanel( 'taxonomy-panel-TAXONOMY-NAME' ) ; //Hide Custom Taxonomy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.