Admin menu as submenu from another plugin

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:

Read More
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.

Related posts

Leave a Reply

1 comment

  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() 
    {
        add_submenu_page(
            'backwpup', // Third party plugin Slug 
            'My plugin', 
            'My plugin', 
            'delete_plugins', 
            'third_party_submenu', 
            'plugin_options_wpse_wpse_91377'
        );
    }
    
    function plugin_options_wpse_wpse_91377() 
    { 
        echo '<h1>OK</h1>'; 
    }
    

    enter image description here