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
.
Trying to simulate the issue, it happened the same (
wp-admin/submenu_slug
), and the solution is to add a priority value in the hookadmin_menu
.Here, I’m adding a sub menu to the plugin BackWPup. Note the priority
11
: