Your code is correct. However there is something missing which it is not obvious at all, and whoever comes to this question again in the future, you should read this:
When a menu page has 0 or 1 submenu pages, no submenus will show up.
A menu page contains a page by itself.
A menu page that contains 1 submenu page, will appear as the same as if it didn't have a submenu page. This is because the first-level menu element and the first second-level menu belonging to that first-level menu are meant to show the same page.
In other words, you can't have a single submenu element, because that doesn't seem to make sense for WordPress.
"Only one page? Just use the menu element itself then! No need for a
dropdown."
Notice that whenever you click on a menu item found in the admin interface that has subitems, it will load its first subitem. So the menu item and its first subitem are essentially the same. However, you are able to rename the subitem.
Some examples of this:
- Dashboard = Home
- Posts = All Posts
- Appearance = Themes
- Tools = Available Tools
So in your case clicking on Wholesale Pricing would load Registrations.
When a menu page contains 2 or more submenu pages, the submenu pages will become visible. That's what most of us don't know at first.
So the trick is to create a submenu page identical to the menu page (you can change the $page_title and $menu_title if you want) and then your additional submenu page:
add_menu_page( '', 'Menu Item', $capability, 'parent_slug', $callback );
add_submenu_page( 'parent_slug', 'Page Title', 'First Subitem', $capability, 'parent_slug', $callback );
add_submenu_page( 'parent_slug', 'Second Page Title', 'Second Subitem', $capability, 'submenu_slug', $submenu_callback );
As you can see, the $page_title
for add_menu_page
could even be left as an empty string (but not null
), because the title used for the page will be the first submenu's $page_title
. But I recommend to introduce the same string for both for readability.
Now let's apply this to your code:
add_menu_page( 'Wholesale Pricing', 'Wholesale', 'manage_options', 'woo-wholesale', 'woo_wholesale_page_call');
add_submenu_page( 'woo-wholesale', 'Wholesale Pricing', 'Pricing', 'manage_options', 'woo-wholesale', 'woo_wholesale_page_call' );
add_submenu_page( 'woo-wholesale', 'Registrations', 'Registrations', 'manage_options', 'woo-wholesale-registrations', 'wwpr_page_call' );
And you will have the following menu structure:
Wholesale
-- Pricing
-- Registrations
Where clicking on either Wholesale or Pricing will lead you to the same page.