0

Is there a way to un register all submenus at once instead of using the code below?

remove_submenu_page('myplugin', 'sub-page-1'); 
remove_submenu_page('myplugin', 'sub-page-2'); 
remove_submenu_page('myplugin', 'sub-page-3'); 
remove_submenu_page('myplugin', 'sub-page-4'); 
remove_submenu_page('myplugin', 'sub-page-5');
...
... 

The idea is...

remove_submenu_page('myplugin', all);??? 

1 Answer 1

2

Not without touching the global $submenu directly (which I wouldn't recommend - using only purposefully exposed APIs provides, in general, better stability).

However, if you wanted a function to remove all submenus:

/**
 * Removes all submenus of given menu item
 *
 * @param string $menu_slug The slug of the parent menu to remove submenus of
 */
function wpse137406_remove_submenus( $menu_slug ) {
    global $submenu;

    if ( isset( $submenu[$menu_slug] ) ){
         unset( $submenu[$menu_slug] );
    }
}
1
  • Okay well ill skip the use of the global and stick to some extra lines of code....thanks!
    – user759235
    Commented Mar 10, 2014 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.