I am using this code:
add_menu_page($page_title, $menu_title, $this->capability, $menu_slug, $function);
Which is adding top level admin page. When I add:
add_submenu_page( $menu_slug, 'sub menu 1', 'sub menu 1', $this->capability, $menu_slug . '_sub_menu_page_1', $function );
I get not only the desired child page, but also the parent page moves to become a child page of itself.
Unless I misunderstand the question, this should do the trick:
EDIT:
Here’s the easiest way to hide the first sub-menu item.
1) Create admin.css and move it to /[your template dir]/css/
2) Add this to your admin.css:
3) Add the following code to your functions.php
use remove_submenu_page() like this :
ok, parent_menu links to the first submenu page.
The standard trick is to repeat the main menu page as a submenu page, without the menu title (3rd parameter).
That will give you
Is there some reason that you don’t just use
remove_submenu_page()
as applicable to remove the page being added, and then just build (or re-build, as the case may be) your menu structure?But really, that would be a hack, and the need to use a hack is indicative of something doing wrong that needs to be fixed. For that, we’ll probably need the actual code being used.
add_action( ‘admin_menu’, ‘my_admin_menu’ );
function my_admin_menu() {
add_menu_page( ‘Optins’, ‘Theme Options’, ‘manage_options’, ‘options’, ‘options_admin_page’, ‘dashicons-admin-generic’, 6 );
add_submenu_page( ‘options’, ‘First Sub Options’, ‘First Option’, ‘manage_options’, ‘options’, ‘options_admin_sub_page_first’ );
add_submenu_page( ‘options’, ‘Second Sub Options’, ‘Second Option’, ‘manage_options’, ‘second-option’, ‘options_admin_sub_page_second’ );
}
function options_admin_page(){
}
function options_admin_sub_page_first(){
}
function options_admin_sub_page_second(){
}