Reading list Switch to dark mode

    How to add submenu in WordPress admin panel

    Updated 12 April 2024

    Submenus are menu items listed below your top-level menu and menu item listed below existing default menus in WordPress admin panel. We will examine how to make a submenu in admin panel WordPress. I assumed, you are created a menu or add to the default menu in the admin panel. Here, we created a menu named Webkul Products as shown in image below :-

    add-menu-to-wordpress

    You can see how to add a menu to WordPress admin panel.

    Now we are creating a submenu named Add Product under the Menu( Webkul Product -> Add Module )

    You can use add_submenu_page() function explained below: –

    add_submenu_pagestring $parent_slugstring $page_titlestring $menu_titlestring $capabilitystring $menu_slugcallable $callback = ”, int|float $position = null ): string|false

    Searching for an experienced
    WordPress Company ?
    Find out More

    This function takes a capability which will be used to determine whether or not a page is included in the menu.

    The function which is hooked in to handle the output of the page must check that the user has the required capability as well.

    Parameters

    1. $parent_slug ( string Required ) :- This slug passed as name for the parent menu or you can pass the file name of a standard WordPress admin page.
    2. $page_title ( string Required ) :- This text will displayed in the page as title tags when we will select the menu.
    3. $menu_title ( string Required ) :- This will display text on menu as label
    4. $capability ( string Required ) :- Capability is required for displaying menu item
    5. $menu_slug ( string Required ) :- This slug name is refer to menu and should be unique for this menu item and will only include alphanumeric, lowercase , dashes, and underscores letter.
    6. $callback ( callable Optional ) :-
    7. $position ( int|float Optional ) :- A function to call to return the content of this page.
      Default is : null
    8. $position ( int|float Optional ) :- The position in the menu order to display this item.
      Default is : null

    Just follow these steps and add this code in function.php file :-

    1. Create a custom function and use add_submenu_page() :-

    Function Definition

    2. Create callback function and pass in add_submenu_page() : –

    Callback Function

    3. Now add a function to add_action with an action hook ( admin_menu ) : –

    add-action-submenu

    add_action -> Add a callback function to your action hook.

    admin_menu -> Fires earlier than the admin menu is loaded in Admin.

    add_action -> admin_menu
    add-a-submenu-to-wordpress

    Output:-

    add-submenu-to-wordpress

    If you need custom WordPress Development services then feel free to reach us and also explore our exclusive range of WordPress WooCommerce Plugins.

    Reference

    https://developer.wordpress.org/reference/functions/add_submenu_page/#parameters

    !!Have a Great Day Ahead!!

    Supported Framework Version - Wordpress Higher 5.5

    . . .

    Leave a Comment

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


    1 comments

  • abhinab gogoi
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home