The add_menu_page
documentation says to pass the menu title as the second parameter:
add_menu_page('Page Title', 'Menu Title', ...);
When adding more pages later via add_submenu_page
, the main page becomes the first entry in the submenu:
However, I want the first item in the list to have a different name (but still point to the same page), the way WordPress itself does it:
How could I accomplish that in my plugin?
You can make the ‘slug’ for the submenu page equal that of the top level page, and they’ll point to the same place:
add_action('admin_menu', 'my_menu_pages');
function my_menu_pages(){
add_menu_page('My Page Title', 'My Menu Title', 'manage_options', 'my-menu', 'my_menu_output' );
add_submenu_page('my-menu', 'Submenu Page Title', 'Whatever You Want', 'manage_options', 'my-menu' );
add_submenu_page('my-menu', 'Submenu Page Title2', 'Whatever You Want2', 'manage_options', 'my-menu2' );
}
E.g.