I would like to add my new developed plugin's admin menu to an existing plugin as sub menu. Would be possible to do this?

In my first plugin I initilize the menus as follows:

function add_pages() {
    // Add a new top-level menu (ill-advised):
    add_menu_page(__('MyMenu','menu-test'), __('MyMenu','menu-test'), 'manage_options', 'menu-top-level-handle', array ($this , 'menu_toplevel_page' ) );

    // Add a second submenu to the custom top-level menu:
    add_submenu_page('menu-top-level-handle', __('Test Submenu','menu-test'), __('Test Submenu','menu-test'), 'manage_options', 'sub_page_test', array($this , 'test_sublevel_page2') );

The code in the second plugin:

function admin_menu () {    
    add_submenu_page( 'menu-top-level-handle', 'Lexikon', 'Lexikon', 'manage_options', 'lexikon-edit', array($this , 'lexikon_settings_page') );

Then I tried the following in my second plugin, but the page is wrong redirected instead: admin.php?page=sub_page redirects to /sub_page.


1 Answer 1


Trying to simulate the issue, it happened the same (wp-admin/submenu_slug), and the solution is to add a priority value in the hook admin_menu.

Here, I'm adding a sub menu to the plugin BackWPup. Note the priority 11:

add_action('admin_menu', 'third_party_submenu_wpse_91377', 11 );

function third_party_submenu_wpse_91377() 
        'backwpup', // Third party plugin Slug 
        'My plugin', 
        'My plugin', 

function plugin_options_wpse_wpse_91377() 
    echo '<h1>OK</h1>'; 

enter image description here

  • More specifically, the priority of the action that adds the submenu item must be a higher number than the action that created the original menu. Otherwise your plugin will try to add a submenu to an item that hasn't been created yet.
    – CragMonkey
    Oct 20, 2020 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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