How can i remove the whole menu in the admin?

I have this code:

function remove_menu_items() {
    global $menu;

    end( $menu );

    while ( prev($menu) ) {
        $value = explode( ' ', $menu[ key($menu) ][0] );
        if ( $value[0] != NULL ? $value[0] : "" ) {
            unset( $menu[ key($menu) ] );
add_action( 'admin_menu', 'remove_menu_items' );

This only removes the default menu items, any pages added to the menu by a plugin are still there.

How can i remove the whole menu?

add_action('admin_head', 't5_hide_menu');
function t5_hide_menu()
    $GLOBALS['menu'] = array();
<style>#adminmenuback,#adminmenuwrap{display:none !important}
#wpcontent, #footer{margin-left:0 !important}</style>

Now I want to know: why? :)

  • +1 for "Now I want to know: why? :)" Btw: (not sure) Isn't the adminmenu or admin_menu (or even _admin_menu) hook more appropriate for this? – kaiser Feb 14 '12 at 21:55
  • @kaiser I like it when my style elements are placed in the <head>. Therefore it’s admin_head. – fuxia Feb 15 '12 at 0:34
  • Note to later readers: This (empty array) is the only solution that will successfully prevent an error if plugins add pages later on. @toscho If you dump the global at for e.g. admin_footer, I guess there'll be left overs from plugins that hook later. Imho would be better to split this into two functions and go into adminmenu with a really high priority. – kaiser Feb 15 '12 at 0:45
  • 1
    It's very important to note that hiding the menu won't prevent users from accessing the pages directly if they know the URI. Otherwise it's just an illusion, like an aztec tomb. – Matthew Boynes Feb 15 '12 at 4:24
  • thanks I should have said i dont want to do it using css or javascript. I want to do this as I am styling the admin and using my own menu. – Lee Feb 15 '12 at 9:17

Use the following to remove the entire thing:

global $menu;

Hope this helps!

Btw, the admin menu code is in /wp-admin/menu.php if you want to look at it and mess with certain items.

  • +1 But I guess it will throw an error if some plugin tries to add stuff to a non existing array. – kaiser Feb 15 '12 at 0:41
  • this doesnt work – Lee Feb 15 '12 at 9:16
  • You're supposed to put that code in a function which is hooked to admin_head. ie. function noMenu() { global $menu; unset($menu); } and then add_action('admin_head', 'noMenu'); – Vlad Ionescu Feb 15 '12 at 17:54
  • yes i did that thanks but ended up with lots of errors – Lee Mar 9 '12 at 18:03

You could use CSS:

#adminmenuwrap { display:none; }

Or you could use Javascript and hide each element.

Target #menu-media, #menu-links and so on.

Or you could do this:

add_action( 'admin_menu' , 'i_can_haz_no_menuz' );
function i_can_haz_no_menuz() {
    global $menu;
    $menu = array();

Just remember that other plugins may add menus after this point.

  • +1 But are you shure you don't get an error when setting it to null? – kaiser Feb 15 '12 at 0:41
  • thanks I should have said i dont want to do it using css or javascript. I tried you code and it didnt remove the pages added by plugins. It might be that i need to use another hook – Lee Feb 15 '12 at 9:20
  • I tried: function remove_menu_items() { global $menu; $menu = null; } add_action('admin_menu', 'remove_menu_items', 12); But i got errors – Lee Feb 15 '12 at 9:35
  • probably should be an array instead of null – Sterling Hamilton Feb 15 '12 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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