• Resolved euphogeeza

    (@euphogeeza)


    Hi all,

    I have written a plugin that adds an admin menu to the Admin interface and a couple of submenus. I used…

    add_menu_page(‘MY_MENU_ITEM’,’MY_MENU_ITEM’,’manage_options’,’my-menu-item-slug’,’my_menu_item_func’);
    add_submenu_page(‘my-menu-item-slug’,’SubMenu1′,’SubMenu1′,’MyCapability’,’sub-slug-1′,’sub_func_1′);
    add_submenu_page(‘my-menu-item-slug’,’SubMenu2′,’SubMenu2′,’MyCapability’,’sub-slug-2′,’sub_func_2′);

    What I get is a menu that looks like…

    MY_MENU_ITEM
    |–MY_MENU_ITEM
    |–SubMenu1
    +–SubMenu2

    I have tried using the remove_submenu_page() immediately after the add_menu_page() function but the second MY_MENU_ITEM persists.

    add_menu_page(‘MY_MENU_ITEM’,’MY_MENU_ITEM’,’manage_options’,’my-menu-item-slug’,’my_menu_item_func’);
    remove_submenu_page(‘MY_MENU_ITEM’,’MY_MENU_ITEM’);
    add_submenu_page(‘my-menu-item-slug’,’SubMenu1′,’SubMenu1′,’MyCapability’,’sub-slug-1′,’sub_func_1′);
    add_submenu_page(‘my-menu-item-slug’,’SubMenu2′,’SubMenu2′,’MyCapability’,’sub-slug-2′,’sub_func_2′);

    How do I remove the “MY_MENU_ITEM” submenu?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    You cannot really. You can re-label it by adding a submenu right after the main menu with the same slug as the parent slug. This is what all the default menus do.

    You can hide it with CSS. Each top level menu item has a unique ID and the first submenu has the class wp-first-item, so the first item is easily targeted without affecting other menu items.

    Thread Starter euphogeeza

    (@euphogeeza)

    Thanks bcworkz,

    Using…

    add_menu_page(‘MY_MENU_ITEM’,’MY_MENU_ITEM’,’manage_options’,’my-menu-item-slug’,’my_menu_item_func’);
    add_submenu_page(‘my-menu-item-slug’,’′,’′,’MyCapability’,’my-menu-item-slug′);
    add_submenu_page(‘my-menu-item-slug’,’SubMenu1′,’SubMenu1′,’MyCapability’,’sub-slug-1′,’sub_func_1′);
    add_submenu_page(‘my-menu-item-slug’,’SubMenu2′,’SubMenu2′,’MyCapability’,’sub-slug-2′,’sub_func_2′);

    …worked.

    ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How do I remove the auto-created submenu item below an admin menu.’ is closed to new replies.