• 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

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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.

    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.

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add menu page without submenu’ is closed to new replies.