I created a custom post type named portfolio with tag taxonomy support.
Since WP does not make a difference between post tags and custom post type tags, I created a menu item Taxonomy under which I want to put categories and post tags. I managed to create the the menu and submenus, and also remove category and post tags from the Post menu, but i didn’t manage to remove Post Tags from the custom post type menu.
I tried:
remove_submenu_page( 'edit.php?post_type=portfolio', 'edit-tags.php?taxonomy=post_tag&post_type=portfolio' );
You can use
remove_submenu_page()
– the trick however is to get the slug exactly right, to do this the easiest way is to dump the global $submenu and check for the menu_slug and submenu_slug.This will give you the array of menus, the top level key is the menu_slug and then the correct submenu_slug can be found in the element 2 of the nested arrays.
So if I had a custom post type called “my_events” and I wanted to remove the tags menu from it, my original menu structure would look like this
From this you can see that the menu_slug is
'edit.php?post_type=my_events'
and the submenu slug for the tags menu is'edit-tags.php?taxonomy=post_tag&post_type=my_events'
.So the remove function call would be:
Note that the submenu slug is html encoded so the ampersand is now
&
– this is probably that thing that has made it hard for people to work out from first principles what the slug name should be.This is a bit dirty, but it works:
I’m not sure exactly which key number you’ll want to remove. Best way to find that is to do:
Everything will break when you load the admin area until you remove that line, but it’ll show you the structure and which key you need.
It might be better to just use the
'show_ui' => false
.To build on the answer from benz001:
No need to do the var dump to get the slug right. This worked for me.
First argument, replace POST_TYPE with what you see in your URL field at the top of the browser when viewing archive in back end.
Second Argument: Left click on the submenu you want to remove, copy the link, remove the last forward slash and everything to the left of it. Replace the & with &
Second arg example below.
1 Copy and paste submenu link
2 Remove last forward slash and everything left of it.
3 Replace the & with the HTML entity &