In the theme admin menu below, the “MyTheme Menu Label” is being duplicated twice on the sidebar menu, once for the main menu link and again for the first submenu link.
How can I remove the 2nd instance of the link
add_menu_page(
"MyTheme",
"MyTheme Menu Label", //THIS IS REPEATED TWICE IN THE MENU
"edit_themes",
"functions.php",
'theme_admin',
get_bloginfo('template_directory') .'/img/favicon.png',31
);
add_submenu_page(
'functions.php',
"SEO Options",
"SEO",
'edit_themes',
'my-seo-options',
'theme_admin'
);
add_submenu_page(
'functions.php',
"Misc Options",
"Misc",
'edit_themes',
'my-misc-options',
'theme_admin'
);
//etc...
There is a workaround to hide this automatically created submenu. In the past I’ve used it quite often, but lately I have returned to leaving it as is (or renaming it, as m0r7if3r suggested).
Also note, that aside your main question, you have switched the positions of the menu_slug and function arguments in
add_menu_page
, see the codex for reference.This is how it is done anyhow:
This isn’t too clean, but afaik the only way to hide the duplicate submenu.
From the codex page on admin menus:
Personally, I think that it would be bad practice to do anything but rename the top link, as it would break consistency with the rest of the admin bar.
There’s a function that should cover this: