How to add custom menu and submenu in wordpress admin

This tutorial is used to create menu and submenu in wordpress admin.

just follow these step.

1. create a function named first_custom_menu and place it in “admin_menu” action, like this code

function first_custom_menu(){
}
add_action('admin_menu', 'first_custom_menu');


2. at first, add a menu in that function using add_menu_page, like this code

function first_custom_menu(){
add_menu_page('First Custom Menu', 'First Custom Menu label', 'manage_options', 'first-custom-menu-options', 'wp_first_custom_menu_func');
}

3. then, add a sub-menu in that function using add_submenu_page, like this code

function first_custom_menu(){
add_menu_page('First Custom Menu', 'First Custom Menu label', 'manage_options', 'first-custom-menu-options', 'wp_first_custom_menu_func');
add_submenu_page( 'first-custom-menu-options', 'First Custom Sub-Menu', 'First Custom Sub-Menu label', 'manage_options', 'first-custom-submenu-options', 'wp_first_custom_submenu_func');
}

4. the complete snippet is this,

<?php 

function first_custom_menu(){
  add_menu_page('First Custom Menu', 'First Custom Menu label', 'manage_options', 'first-custom-menu-options', 'wp_first_custom_menu_func');

  add_submenu_page( 'first-custom-menu-options', 'First Custom Sub-Menu', 'First Custom Sub-Menu label', 'manage_options', 'first-custom-submenu-options', 'wp_first_custom_submenu_func');

  add_submenu_page( 'first-custom-menu-options', 'Second Custom Menu', 'Second Custom Menu label', 'manage_options', 'second-custom-submenu-options', 'wp_second_custom_submenu_func');

}

add_action('admin_menu', 'first_custom_menu');

function wp_first_custom_menu_func(){
?>
<div class="wrap">
    <div id="icon-options-general" class="icon32"><br></div>

    <h2>First Custom Menu Page</h2>
</div>
<?php
}
function wp_first_custom_submenu_func(){
?>
<div class="wrap">
    <div id="icon-options-general" class="icon32"><br></div>

    <h2>First Custom Sub-Menu Page</h2>
</div>
<?php } 

function wp_second_custom_submenu_func(){
?>
<div class="wrap">
    <div id="icon-options-general" class="icon32"><br></div>

    <h2>Second Custom Sub-Menu Page</h2>
</div>
<?php } ?>

That is all for Now.