12

I need to customize the admin panel for my user. So how do I remove the entire admin menu? Not remove the menu item, I mean entirely remove the left vertical menu bar, include the design of the menu (eg, css, background..etc). I want it become blank.

I can do it by css hack. But I prefer to use hook to do it. Any ideas?

Thanks

  • I'm curious. If your users don't need access to any of the admin menu items, why do they need access to the dashboard at all? – moraleida May 15 '12 at 1:35
  • Wondering on the motives... Do you want to hide it for specific roles/users? Are you making a custom Admin Bar menu (at the top)? – brasofilo May 15 '12 at 1:49
  • 1
    Yes, I would like to customize the admin menu. Not that the current admin menu is not good enough, it just too 'wordpress' feel. Not good for branding, in my opinion. – dev-jim May 15 '12 at 11:05
  • Please check my previous answer here; wordpress.stackexchange.com/questions/136058/… – numediaweb Sep 7 '14 at 15:46
14

The correct hook to use is admin_menu and then create a function to remove the menus you want to remove. The following 2 functions remove all the menus.

add_action( 'admin_menu', 'remove_admin_menus' );
add_action( 'admin_menu', 'remove_admin_submenus' );

//Remove top level admin menus
function remove_admin_menus() {
    remove_menu_page( 'edit-comments.php' );
    remove_menu_page( 'link-manager.php' );
    remove_menu_page( 'tools.php' );
    remove_menu_page( 'plugins.php' );
    remove_menu_page( 'users.php' );
    remove_menu_page( 'options-general.php' );
    remove_menu_page( 'upload.php' );
    remove_menu_page( 'edit.php' );
    remove_menu_page( 'edit.php?post_type=page' );
    remove_menu_page( 'themes.php' );
}


//Remove sub level admin menus
function remove_admin_submenus() {
    remove_submenu_page( 'themes.php', 'theme-editor.php' );
    remove_submenu_page( 'themes.php', 'themes.php' );
    remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=post_tag' );
    remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=category' );
    remove_submenu_page( 'edit.php', 'post-new.php' );
    remove_submenu_page( 'themes.php', 'nav-menus.php' );
    remove_submenu_page( 'themes.php', 'widgets.php' );
    remove_submenu_page( 'themes.php', 'theme-editor.php' );
    remove_submenu_page( 'plugins.php', 'plugin-editor.php' );
    remove_submenu_page( 'plugins.php', 'plugin-install.php' );
    remove_submenu_page( 'users.php', 'users.php' );
    remove_submenu_page( 'users.php', 'user-new.php' );
    remove_submenu_page( 'upload.php', 'media-new.php' );
    remove_submenu_page( 'options-general.php', 'options-writing.php' );
    remove_submenu_page( 'options-general.php', 'options-discussion.php' );
    remove_submenu_page( 'options-general.php', 'options-reading.php' );
    remove_submenu_page( 'options-general.php', 'options-discussion.php' );
    remove_submenu_page( 'options-general.php', 'options-media.php' );
    remove_submenu_page( 'options-general.php', 'options-privacy.php' );
    remove_submenu_page( 'options-general.php', 'options-permalinks.php' );
    remove_submenu_page( 'index.php', 'update-core.php' );
}

Screenshot of left menu using the above 2 functions:

enter image description here

  • 3
    I did find another way by using $GLOBALS['menu'] = array();. Giving null in the array will also do the work. – dev-jim May 15 '12 at 11:13
  • Where do you put this? – user26728 Jul 17 '13 at 14:22
  • Anyone noticed the recent drafts from that screen shot? ;) – acSlater Sep 24 '13 at 15:02
4

Following the lead of /wp-admin/admin-header.php -> /wp-admin/menu-header.php there's no hook to do it.

A solution is to hook in admin_head and do some CSS + jQuery

add_action('admin_head', 'wpse_52099_script_enqueuer');
function wpse_52099_script_enqueuer(){
    if(!current_user_can('administrator')) {
        echo <<<HTML
        <style type="text/css">
        #wpcontent, #footer { margin-left: 0px; }
        </style>
        <script type="text/javascript">
        jQuery(document).ready( function($) {
            $('#adminmenuback, #adminmenuwrap').remove();
        });     
        </script>
HTML;
    }
}

[update]
As per a clarification to the question, where it gets clear that the motivation is branding the admin area, these are the 4 plugins that I use for that:

  • Adminimize (hide large chunks of WordPress interface, filtering by role)
  • Ozh' Admin Drop Down Menu (all admin menu in a horizontal CSS driven drop down menu)
  • Admin Menus Fixed (perfect companion for Ozh's)
  • Admin Tweaks (I'm the author of this one, and it's main purpose is customizing many areas of the admin interface)
  • If you go this route, it makes more sense to use wp_enqueue_script() with admin_enqueue_script hook. – mrwweb May 15 '12 at 1:55
  • 1
    @mrwweb Even when it is such a small insertion? Do you think is worthy? – brasofilo May 15 '12 at 2:01
  • Agreed. Small script/style insertions are more easily done with admin_head. – chrisguitarguy May 15 '12 at 3:18
  • I don't like using the jquery unless I have no other choice. What if the visitors disable the javascript on their browser? Though, there is not likely to happen, but there is the possibility there. Anyway thanks for the advice. – dev-jim May 15 '12 at 11:10
  • In my example, it'll be a matter of double removing by also hiding the 2 divs in CSS as well. – brasofilo May 15 '12 at 12:06
2

The only hook-friendly way I know is to use remove_menu_page() for every single menu item. Even then, I don't know what happens to the left bar itself (whether it would collapse down to 0px width or what). Even with using the hooks, I imagine at some point you'll want to enqueue an admin stylesheet to cleanup what remains of the menu markup styles.

I would be careful about doing this. For instance, if you remove "Settings," then any plugins that creates menu pages in the "Settings" menu can't be reached. In general, I wonder how sustainable it really is to completely remove the menu.

  • I am sure he was looking for a way to remove the menu for regular users, not admins. :) – Christine Cooper Mar 18 '15 at 15:56
1
add_action( 'admin_menu', 'remove_admin_menus' );

function remove_admin_menus(){
    global $menu;
    $menu = array();
}
  • This answer is very handy too. It is short and works like a charm, except for the menu pages created by plugins. (which should not be a problem because they are only visible for an administrator) – Charles Apr 26 '18 at 13:39
  • It is a handly solution, indeed, BUT it is worth saying that it won't actually block access to those admin pages, it will just make them invisible in the admin bar. It is better than a CSS solution for hiding items, of course, but still flawed in terms of security: savy users can still get direct access to admin pages by editing the URL. – Marcos Buarque Jun 9 '18 at 14:47
0

I improve the solution of @brasofilo as it is have small bug - on page reload with not best internet connection menu will appear for very short time. To avoid it I added a bit of more css:

add_action('admin_head', 'wpse_52099_script_enqueuer');

function wpse_52099_script_enqueuer() {

    if(!current_user_can('administrator')) { 

echo <<<HTML
<style type="text/css">
#wpcontent, #footer { margin-left: 0px !important; }
#adminmenuback, #adminmenuwrap { display: none !important; }
</style>
<script type="text/javascript">
jQuery(document).ready( function($) {
    $('#adminmenuback, #adminmenuwrap').remove();
});
</script>
HTML;

    }
}

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.