Menu Close

    How to add menu in WordPress admin panel

    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.

    As we know WordPress provide hook using which we can easily add custom admin menu. So, for this we’ll use ‘admin_menu’ hook and add action to this hook

    1. Creating menu –

    Add this code in functions.php file of your plugin or theme.

    add_action('admin_menu', 'custom_menu');

    In above line of code, first parameter is the hook we discuss about, Second parameter is name of callback function. In callback function you have to write what you want to alter in admin menu.

    function custom_menu() { 
    
      add_menu_page( 
          'Page Title', 
          'Menu Title', 
          'edit_posts', 
          'menu_slug', 
          'page_callback_function', 
          'dashicons-media-spreadsheet' 
    
         );
    }

    As you can see in 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.

    Start your headless eCommerce
    now.
    Read More

    In 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 one is capability, The capability required for this menu to be displayed to the user. You can find a list of all WordPress capabilities here – https://codex.wordpress.org/Roles_and_Capabilities
    • Fourth parameter is menu slug, which is used for creating page URL. Keep this unique.
    • Fifth parameter is page callback function. The function to be called to output the content for this page.
    • Sixth parameter is for icon, either you can provide a URL of image or you can choose predefined WordPress icons. https://developer.wordpress.org/resource/dashicons/

    Wordpress Dashboard

    Reference – https://themes.artbees.net/blog/wordpress-custom-admin-pages/

    Support

    Still have any issues feel free to add a ticket and let us know your views to make the code better create a ticket.

    Thanks for Your Time! Have a Good Day! Also, Hire WooCommerce Developers for all kinds of services for web and mobile development, plugin development, mobile app, design services, and much more.

    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    15 comments

  • phptechie
    This is an amazing tutorial! Thank you very much, it was very beneficial to me.
    • Zeba Hakim (Moderator)
      Hello There,
      Thanks for the valuale words. Keep tuned in for more of such knowledgeable content.
      Further, if you have any requirements kindly feel free to contact us on [email protected]

      Thanks and Regards.

  • Sonu kumar
    i have plugin with short code from which in used to insert data into database from post and pages
    but now i want to insert data from admin panel menu how i do that
    • Sagar Bansal (Moderator)
      Hello,

      For this, you need to create a form in your backend and on submitting form run the SQL query to insert the data as per your need.

      Thanks,
      Sagar Bansal

  • sagar sharma
    function custom_menu() {

    add_menu_page(
    ‘Page Title’,
    ‘Menu Title’,
    ‘edit_posts’,
    ‘menu_slug’,
    ‘page_callback_function’,
    ‘dashicons-media-spreadsheet’

    );
    }
    thans sir provide this source code
    https//:www.bvmgroups.com

    • Mohit Verma (Moderator)
      Hello,

      page_callback_function is a callback function where you will do code which you want.

      Thanks & Regards
      Mohit verma

  • Nasiruddin Khan
    Nice about Admin menu in wordpress
    • Mohit Verma (Moderator)
      Thanks for the appreciation!
  • Eren
    Hey
    I have an issue

    I would like to customize my WordPress Dashboard Menu with adding codes.
    I tried following code block to remove “Tools” and “Users” from menu, and it worked:

    function wpexplorer_remove_menus() {
    remove_menu_page( ‘users.php’ );
    remove_menu_page( ‘tools.php’ );
    }
    add_action( ‘admin_menu’, ‘wpexplorer_remove_menus’ );

    But for instance, I’m trying to remove “SliderRevolution” from menu but it’s failing.
    SliderRevolution is a menu which contains sub-menus under them.

    When I look “Tools” menu’s php name, it seems as tools.php
    and when I look SliderRev name, it seems as admin.php?page=revslider

    I tried this code and it didn’t work :
    remove_menu_page( ‘admin.php?page=revslider’ );

    Which code can I use to remove this RevolutionSlider and the other menu elements like this ?

  • Ben
    add_action(‘newsflash’, ‘newsflash’);
    function custom_menu() {

    add_menu_page(
    ‘Newsflash’,
    ‘Newsflash’,
    ‘edit_pages’,
    ‘newsflash’,
    ‘newsflash’,
    ‘dashicons-welcome-widgets-menus’, 90);
    }

    // remove admin bar
    // add_filter(‘show_admin_bar’, ‘__return_false’);

    ?>

    There is a syntax error, unexpected ‘show_admin_bar’ (T_STRING), expecting ‘)’ please help with the menu code and the error, relatively new to PHP. Sorry 🙁

    • Mohit Verma (Moderator)
      Hello Ben,

      Greetings!

      Thanks for the comment.

      We have checked your issue.

      add_action(‘newsflash’, ‘newsflash’);

      It’s not a right way to use admin hook.

      Please use updated code.

      add_action(‘admin_menu’, ‘custom_menu’);

      ‘admin_menu’ : it’s a hook tag use for admin menu.
      ‘custom_menu’ : it’s a callback function use to do the all stuffs.

      If you have any query, feel free to ask. We are here to help you.

      Thanks & Regards

      Mohit verma

  • pradeep
    –submenu notshowing issue—
    add_menu_page(‘Safety Checklist’, ‘Safety Checklist’, ‘manage_options’, ‘option_checklist.php’, ”, ‘dashicons-welcome-widgets-menus’, 90);
    add_submenu_page(‘checklist_category.php’, ‘Manage Checklist Category’, ‘Manage Checklist Category’, 82, ‘checklist_category.php’, ‘checklist_category.php’);
    • Mohit Verma (Moderator)
      Hello,

      We have checked and fixed your issue.

      Please use all the parameters in right way.

      Updated code:

      add_menu_page(‘Safety Checklist’, ‘Safety Checklist’, ‘manage_options’, ‘option_checklist’,’option_checklist’, ‘dashicons-welcome-widgets-menus’, 90);
      add_submenu_page(‘option_checklist’, ‘Manage Checklist Category’, ‘Manage Checklist Category’,’manage_options’,’option_checklist_submeu’,’option_checklist_sub’);

      Note:-

      option_checklist is a callback function of main menu.
      option_checklist_sub is a callback function of sub-menu.

      do all the stuffs in callback functions.

      Still have any issue feel free to add a ticket and let us know your views to make the code better https://webkul.uvdesk.com/en/customer/create-ticket/

      • Coto
        Does the submenus php as well as callback have to be in the same php page as main menu? Or should they be separately written?
        • Mohit Verma (Moderator)
          Hello,

          You can write code in any file but sub-menu action can access the callback function. Main menu action and sub-menu action should be in same php file.

          Still have any issue feel free to add a ticket.
          https://webkul.uvdesk.com/en/customer/create-ticket/

  • Back to Top

    Table of Content