wordpress Admin Menu shows duplicate entry

Hello am working on wordpress plugin and facing an issue while adding links in admin menu, am making a submenue
but it show duplicate entry.
Top level menu repeats in submenu I dont know why
please help
screen shots attached.
Admin Menu Pic

My function

Related posts

3 comments

  1. By default the first submenu item is meant to be a clone of the main menu item, you can however change it.

    From: codex.wordpress.org/Adding_Administration_Menus

    “In situations where a plugin is creating its own top-level menu, the
    first submenu will normally have the same link title as the top-level
    menu and hence the link will be duplicated. The duplicate link title
    can be avoided by calling the add_submenu_page function the first time
    with the parent_slug and menu_slug parameters being given the same
    value.”

  2. The Duplicate Sub-menu Item can be removed using the remove_submenu_page function:

    add_menu_page('Page Title', 'Menu Title', 'manage_options', 'menu-slug', 'my_settings_page');
    
    add_submenu_page('menu-slug', 'Sub Page Title', 'Sub Menu Title', 'manage_options', 'sub-menu-slug', 'my_settings_sub_page');
    
    remove_submenu_page('menu-slug', 'menu-slug');
    

    Use:

    remove_submenu_page( string $menu_slug, string $submenu_slug );

    Note that the sub-menu slug is the same as the top level menu slug.

  3. Solution mentioned above didn’t work without adding a priority of “1” to my

    add_action('admin_menu', 'myplugin_add_submenu') 1);
    

    This finally solved the issue with duplicated menu item.

Comments are closed.