Create navigation menu in admin side in wordpress custom theme

Menu in WordPress admin panel – In this post we see how we can add custom menu to admin sidebar. Sometimes when we work with plugins or theme and we need to show some features or any information in admin page then we can use this code snippet to create the same.

functions.php (create main manu only)

// create main menu

function test_admin_menu() { 

   add_menu_page( __( 'My Events', 'My Events' ), 
                  __( 'Events', 'My Events' ), 
                 'manage_options', 'my-events', 
                 'test_admin_page_contents_fun', 
                 'dashicons-admin-home', 10 ); 
   } 

add_action( 'admin_menu', 'test_admin_menu' );


function test_admin_page_contents(){
   echo "hi";
}
functions.php (create main and sub manu both) 

function test_admin_menu() { 

   add_menu_page( __( 'My Events', 'My Events' ), 
                  __( 'Events', 'My Events' ), 
                 'manage_options', 'my-events', 
                 'all_event_fun', 
                 'dashicons-admin-home', 10 ); 

   add_submenu_page('my-events', __('Page Title - my events', 
   'my-events'), __('All Events', 'my-events'), 
   'manage_options', 'my-events', 
   'all_event_fun'); 

   add_submenu_page('my-events', __('Page Title - add event', 
   'add-event'), __('Add Event', 'add-event'), 
   'manage_options', 'add-event', 
   'add_event_fun'); 

}

add_action( 'admin_menu', 'test_admin_menu' );


function all_event_fun(){
    echo "all event";
}

function add_event_fun(){
    echo "add event";
}

 

 

 

 

 

Leave a Reply