• Resolved nchambers

    (@nchambers)


    Hello! I’m making a small MU plugin, and have ran into a small issue. I have a menu entry in the administrator dashboard that looks like this: https://i.imgur.com/6UpZYwD.png but I was hoping to have it look like this: https://i.imgur.com/4P5f5yL.png. Essentially, I’d like the add_menu_page function to not create a corresponding sub-menu item. I see that plugins like WordFence are able to achieve this, but I couldn’t find any examples online showing how. Is there a setting I’m missing? Here is the code I’m using to generate the menu:

    
    <?php
    
    /**
     * standard boilerplate
     */
    
    defined("ABSPATH") or die("this file can't be run directly");
    
    /**
     * settings menu
     */
    
    add_action("admin_menu", "example_settings_menu");
    
    function example_settings_menu() {
      add_menu_page(
        "Example Plugin",
        "Example Options",
        "manage_options",
        "exop",
        "example_settings",
        "dashicons-archive",
        4
      );
    
      add_submenu_page(
        "exop",
        "Example Plugin",
        "Sub-entry 1",
        "manage_options",
        "sub-one",
        "example_settings_one"
      );
    
      add_submenu_page(
        "exop",
        "Example Plugin",
        "Sub-entry 2",
        "manage_options",
        "sub-two",
        "example_settings_two"
      );
    }
    
    • This topic was modified 5 years ago by nchambers.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Give the first sub-menu item the same menu slug (“exop” instead of “sub-one”) as the main menu page. This causes the sub-menu item data to replace the data auto-created by adding the main menu page. Behind the scenes, WP overwrites the first array element of the global $submenu array that is keyed “exop” instead of adding another keyed “sub-one”.

    Thread Starter nchambers

    (@nchambers)

    That worked perfectly. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Creating an admin dashboard menu without a corresponding submenu entry’ is closed to new replies.