Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm building a plugin that requires its own set of admin pages. I know how to create the top-level link and how to add sub-menus to it. However, what seems to happen is when I create the top-level link, it also automatically adds a submenu page of the same name if I add another submenu page to it.

I'm simply looking for a way to change the name of my first submenu page so that it is different from the parent name. (i.e. in the admin panel, expanding the "Links" menu shows an "All Links" submenu page. Mine would instead say "Links" on top and then "Links" instead of "All Links")

share|improve this question

2 Answers 2

up vote 3 down vote accepted

You just have set the name of the $menu_slug exactly the same as the parent slug.

share|improve this answer
    
Ok, but if I create a top level menu and I'm trying to add submenus to it, WordPress seems to automatically create a new submenu that corresponds to the top level menu name (So there is no submenu to start with, but if I decide to use add_submenu_page and add a new submenu, I get a submenu named the same as the top level and THEN the submenu I just created). Is there somewhere in the add_menu_page() function call where I can specify the name I'd want to give to that automatically created submenu? –  Chiubaka Aug 22 '11 at 4:10
    
Afai-remember: You have to "play" with the names of the slugs. I don't know exactly at the second, but you have to name both equal (on different args) to not get the double menu entry. –  kaiser Aug 22 '11 at 4:53
    
Ok, so I'm playing with it-- looking at the documentation for the add_menu_page function: codex.wordpress.org/Function_Reference/add_menu_page. So the parameters of this function: $page_title - changes the title of the title page (equivalent to typing the title in <title></title>); $menu_title - changes the on-screen name text for the menu, but changes both the top-level and the automatically created submenu; $capability - permissions requirement; $menu_slug - unique slug requirement to be used in the page URL; Are you saying I need to do something with add_submenu_page as well? –  Chiubaka Aug 22 '11 at 18:06
    
Try it with $menu_slug set equal both for parent & child. –  kaiser Aug 22 '11 at 18:08
2  
Yup, that did it. Thanks a ton! That little thing was reaaaally bothering me. –  Chiubaka Aug 22 '11 at 18:42

This is how I solved the parent menu item also being listed as a submenu item:

    if(!function_exists('remove_submenu_page')) {
      unset($GLOBALS['submenu']['parent_menu_slug'][0]);
    }
    else {
      remove_submenu_page('parent_menu_slug','submenu_slug');
    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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