I’m trying to remove a menu item and tried several approaches, but have not had any luck. It was created from a FAQ plugin.
If I use this line:
remove_menu_page( 'edit.php?post_type=question' );
It will remove the main menu, however I only want to remove two sub-menu items contained inside that edit.php?post_type=question
URL address.
For the item I want to remove, the path in the URL bar gives me the following:
edit-tags.php?taxonomy=faq-topic&post_type=question
and
edit-tags.php?taxonomy=faq-tags&post_type=question
I have tried several solutions including remove_menu_page
and remove_submenu_page
to no avail.
What has failed so far:
remove_submenu_page( 'edit.php?post_type=question', 'edit-tags.php?taxonomy=faq-topic&post_type=question');
remove_menu_page( 'edit-tags.php?taxonomy=faq-tags') ;
remove_menu_page( 'edit-tags.php?taxonomy=faq-tags&post_type=question') ;
remove_submenu_page( 'edit.php?post_type=question', 'edit-tags.php?taxonomy=faq-topic&post_type=question');
remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=faq-topic&post_type=question');
remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=faq-topic');
remove_submenu_page( 'edit.php', 'edit-tags.php');
Please read the Codex.
remove_submenu_page()
need two parameters and the right hook.And very important: Use a very, very, very high priority in your hook! If you use a low priority, your function will be executed before the menus will be added. So there is no menu to remove. If you use a high priority, there is a good chance that your function will be executed after the menus was added.
This could be the tricky part.
UPDATE
After installing and inspecting the plugin, I found the solution. There are several issues and a few tricky parts.
The submenus are not added with
add_submenu_page()
, they are added with a custom post type. A simple search byadd_submenu_page()
, copy the menu slugs and removing the menus have to fail. I have to search for the cpt slug and use it.After
global $submenu; var_dump( $submenu );
I get this outputNow it was easy to remove the submenus with
edit.php?post_type=question
as menu slug andedit-tags.php?taxonomy=faq-topic&post_type=question
/edit-tags.php?taxonomy=faq-tags&post_type=question
as submenu slug.If you watch carefully, the ampersand (&) is a html entity. It’s not possible just to copy the url part and insert it. So you cannot remove a submenu page with a un-encoded url, it have to be url-encoded.
And here is the final code:
Make menu item visible only for admin: