Here we see how to add custom menu in admin sidebar. Sometimes when we work with plugins and we need to show some features or any information in admin page we can create menu in admin panel.

By using WordPress hook we can easily add custom menu. For this here we’ll use ‘admin_menu‘ hook and add_action to this hook.

Creating menu –
Add this code in your plugin.

add_action('admin_menu', 'my_custom_menu');

In above code, first parameter is the hook and second parameter is name of callback function.

function my_custom_menu(){
  add_menu_page(
    'Page Title',
    'Menu Title',
    'manage_options',
    'menu_slug',
    'page_callback_function',
    'icon_url'
   );
}

In my_custom_menu() function I just used add_menu_page(). This function allow you to create a menu in admin sidebar and map that menu to a page.

In my_custom_menu() function

First parameter is page title, the title tag of the page when the menu is selected.

Second parameter is menu title. The text to be used for menu title.

Third parameter is capability. The capability required for this menu to be displayed to the user.

Fourth parameter is menu slug, which is used for creating page URL.

Fifth parameter is page callback function. The function to be called to output the content for this page.

Sixth parameter is for icon, you can choose predefined WordPress icons.