Forums

Add menu page without submenu (4 posts)

  1. sulfurito
    Member
    Posted 1 year ago #

    Hello, I'm programming a plugin and in the code I'va added a page and some submenus, the problem I have is the page appears as a submenu also, I have:

    add_menu_page( "Myplugin", "Myplugin", "activate_plugins", "Myplugin", "Myplugin_Entry1");
    add_submenu_page( "Myplugin", "Entry1", "Entry1", "activate_plugins", "Myplugin-Entry1", "Myplugin_Entry1" );
    add_submenu_page( "Myplugin", "Entry2", "Entry2", "activate_plugins", "Myplugin-Entry2", "Myplugin_Entry2" );

    And this does:

    Myplugin
    - Myplugin
    - Entry 1
    - Entry 2

    And I wish to have:

    Myplugin
    - Entry 1
    - Entry 2

    What do I need to do?

    I know I shouldn't have "Myplugin_Entry1" as last parameter in add_menu_page( "Myplugin", "Myplugin", "activate_plugins", "Myplugin", "Myplugin_Entry1"); but otherwise I get an error when clicking menu page.

    Thank you

  2. apimlott
    Member
    Posted 10 months ago #

    Here's a nice hack: In add_menu_page, pass a non-existent capability (and you can leave off the function):

    add_menu_page( "Myplugin", "Myplugin", "nosuchcapability", "Myplugin");

    The automatically-generated submenu is blocked by the capability check.

  3. bbarton
    Member
    Posted 9 months ago #

    Try this

    add_menu_page( $page_title, $menu_title, $capability, $menu_slug, null, $icon_url );
    add_submenu_page( $same_as_add_menu_page_slug, $page_title, $menu_title, $capability, $same_as_add_menu_page_slug, $function );

    add_menu_page has null value as the function.

  4. bbarton
    Member
    Posted 9 months ago #

    Also, only the first add_sub_menu menu-slug needs to be the same as the add_menu_page.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags