Here is a simple example to get you started with the right code. This creates a main menu item using add_menu_page
then attaches a submenu using add_submenu_page
. Both of them call a different function for the output.
Notice that the add_submenu_page
function ties into the parent menu using customteam
which is the $menu_slug
of add_menu_page
.
add_action( 'admin_menu', 'register_my_custom_menu_page' );
add_action( 'admin_menu', 'register_my_custom_submenu_page' );
function register_my_custom_menu_page(){
add_menu_page( 'Team Kit', 'Team Kit', 'manage_options', 'customteam', 'my_custom_menu_page');
}
function register_my_custom_submenu_page() {
add_submenu_page( 'customteam', 'Team info', 'Team info', 'manage_options', 'my-custom-submenu-page', 'my_custom_submenu_page' );
add_submenu_page( 'customteam', 'Crew Stats', 'Crew Stats', 'manage_options', 'my-custom-submenu-page_2', 'my_custom_submenu_page_2' );
//add_submenu_page_3 ... and so on
}
function my_custom_menu_page() {
echo '<p>Hello, I am Team Kit</p>';
}
function my_custom_submenu_page() {
echo '<p>Hello, I am Team Info</p>';
}
function my_custom_submenu_page_2() {
echo '<p>Hello, I am Crew Stats</p>';
}