The menu is generated by the function _wp_menu_output
. If you look at the place where the links are generated (currently lines 158-162 and 170-174) you see that the admin.php?page=
part is omitted under certain circumstances. One of those is an empty $menu_hook
.
The variable menu_hook
is filled by a call to get_plugin_page_hook
, which will return empty if no action is bound to the hook. This translates to: there is no callback function defined to generate the page.
Now let’s look at the hook order: plugins are loaded before themes, so if you generate the submenu before the parent menu (which you do if you initialize the parent menu in the theme’s functions.php
) there might be a problem at line 190-192 of add_submenu_page
: it might not be possible to bind an action to the hook at that point because the parent page is undefined.
Disclaimer: I analysed the code from the top of my head, so I may have made a mistake there.
Anyway, if you insist on initializing stuff from your functions.php
, don’t try to initialize the submenu in your plugin. Instead just define the function in your plugin and call it from the theme as well.