Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 4 down vote accepted
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>
<?php
}

Now I want to know: why? :)

share|improve this answer
    
+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. –  toscho 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

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.

share|improve this answer
    
+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

Use the following to remove the entire thing:

global $menu;
unset($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.

share|improve this answer
    
+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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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