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!
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
tofalse
would completely remove the metabox from the edit screen, the quick edit screen, and the admin menu. But if you setshow_ui
totrue
you can achieve more nuanced control by then using theshow_in_quick_edit
andmeta_box_cb
arguments (setting the later to false hides the metabox on the CPT edit screen as desired).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 thebook
post type like: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:
Or to follow the example above:
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):
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.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:
The lower priority (100) let this code work also if the taxonomies are created by a plugin like CPT-UI.
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.
For
block-script.js
, you can use this code.