3

I have a built a plugin which creates a custom menu like this:

    add_menu_page( 'Wholesale Pricing', 'Wholesale', 'manage_options', 'woo-wholesale', 'woo_wholesale_page_call'); 

I am now trying to add a subpage item underneath this. I have read the codex and came up with:

add_submenu_page( 'woo-wholesale', 'Registrations', 'Registrations', 'manage_options', 'woo-wholesale-registrations', 'wwpr_page_call' ); 

I am guessing this is incorrect as the submenu item isnt showing. Can anyone shed any light on this please?

  • did you used to another class for file submenu . initialization it and define to the main file. – huykon225 Feb 21 '17 at 16:13
7

Make sure that your add_action hook is set to admin_menu.

Here's a sample code:

add_action('admin_menu', 'wpse149688');
function wpse149688(){
    add_menu_page( 'Wholesale Pricing', 'Wholesale', 'manage_options', 'woo-wholesale', 'woo_wholesale_page_call');
    add_submenu_page( 'woo-wholesale', 'Registrations', 'Registrations', 'manage_options', 'woo-wholesale-registrations', 'wwpr_page_call' ); 
}

Also check whether user you've logged in as has the ability to view this menu. As this menu is set using manage_options capability.

2

I made the same mistake as the OP as it is not intuitive how to get this working. By reading the codex on Administration Menus, I discovered the answer.

The problem (for me, anyway) was to edit the $parent_slug parameter in the call to add_submenu_page(...).

So, in the OP's case, you would change:

add_submenu_page( 
    'woo-wholesale', 
    'Registrations', 
    'Registrations', 
    'manage_options', 
    'woo-wholesale-registrations', 
    'wwpr_page_call' 
);

to:

add_submenu_page( 
    'edit.php?post_type=woo-wholesale', 
    'Registrations', 
    'Registrations', 
    'manage_options', 
    'woo-wholesale-registrations', 
    'wwpr_page_call' 
);
  • Worked for me. This should be the accepted answer. Although the OP should have included his 'add_action' line for us all to see, getting the right $parent_slug attribute seems like the more apparent issue. – MarsAndBack Aug 11 '18 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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