Hide the Admin Bar in WordPress

By  on  

WordPress automatically injects an admin toolbar at the top of the page for logged in users.  This bar is really an annoyance to me because it slightly throws off my theme design and I never need the toolbar for anything.  Here's a snippet of code which will prevent that toolbar from displaying:

add_filter('show_admin_bar', '__return_false');

Now I don't need to hide this toolbar with CSS and my layout can look as it should. I love WordPress' filtering/hook system!

Recent Features

  • By
    LightFace:  Facebook Lightbox for MooTools

    One of the web components I've always loved has been Facebook's modal dialog.  This "lightbox" isn't like others:  no dark overlay, no obnoxious animating to size, and it doesn't try to do "too much."  With Facebook's dialog in mind, I've created LightFace:  a Facebook lightbox...

  • By
    fetch API

    One of the worst kept secrets about AJAX on the web is that the underlying API for it, XMLHttpRequest, wasn't really made for what we've been using it for.  We've done well to create elegant APIs around XHR but we know we can do better.  Our effort to...

Incredible Demos

Discussion

  1. I thought there was a setting in WordPress to disable that feature, but I’m not entirely sure. But I agree with you, the admin bar is quite the annoyance.

  2. Or log out and visit your domain…

    It annoys me, too. With this snippet deployed I’m guessing you bookmark `wp-admin` to get back to the dashboard.

  3. You can do this from the dashboard.

    Users>your profile > uncheck Show Toolbar when viewing site

    • Vishal

      That’s the way!

    • Glenn

      BIngo! Atta boy Ahmed.

    • Nicholas

      Thanks for explaining the correct way! I’ve been searching for this fix for days.

  4. I quite like the bar, but I hide it for all users who can’t edit posts (the thing it’s most useful for).

    add_action('set_current_user', 'csstricks_hide_admin_bar');
    function csstricks_hide_admin_bar() {
      if (!current_user_can('edit_posts')) {
        show_admin_bar(false);
      }
    }
    
    • I’m building a dev site for my company. Where do I include the code snippet you’ve shared?

    • Naresh Devineni

      Inside your theme’s functions.php file

  5. Thanks for the snippet, however for users who do not like code play – there is an in-built option in profile settings to hide the admin bar.

    While “Chris Coyier” modification is for sure useful in multi-user setup!

  6. This simple snippet will go into my WordPress core settings file as I find it a pain to have to disable the bar (users -> your profile – > show toolbar) with each new install. Thanks for sharing the snippet.

  7. Milagros Pérez

    David and Chris, thanks!

    This is just what I was looking for :)

  8. I prefer to use the below code in ‘functions.php’ to hide admin bar.

    if (!current_user_can(‘edit_posts’)) {
    show_admin_bar(false);
    }
    
    • Thanks Chankey Pathak,it’s working nicely :)

  9. Thanks Chankey, that did the trick.

  10. I never found the admin bar of much use. Disabling it is the first thing I do after setting up a new WordPress site.

  11. I found the suggestion here leaves a 28px space at the top of my custom theme pages. The following snippet/filter removes it completely. Put it into functions.php in your theme.

    function my_function_admin_bar(){ return false; }
    add_filter( 'show_admin_bar' , 'my_function_admin_bar');
    
    • @adam It worked perfectly! Thank you!

  12. Miikey

    @adam

    thx for the solution, That’s what I was looking for.
    Greetz Miikey

  13. The bar is helpful in editing posts. I just use incognito if I want to test the design without the bar. It’s also helpful in making sure there are any other admin-specific things on the page.

    But another reason to remove the admin bar that was not mentioned in the page: when you want to cache the site to be used by a reverse proxy like cloudflare – you don’t want the admin bar to show…

  14. You can also add this to your functions.php file

    show_admin_bar(false);
    
  15. “You can do this from the dashboard.

    Users>your profile > uncheck Show Toolbar when viewing site”

    Thanks Ahmed – two second job!

    That bar always annoyed me when I’m logged in and checking CSS

  16. Also you can use this code, it will hide admin bar to users that can not manage options

    if ( ! current_user_can( 'manage_options' ) ) {
        show_admin_bar( false );
    }
    
    • @Carlos It worked perfectly. Thanks!

  17. But, if there is no toolbar – how user will log-off?

    Also, how to make members to log-in but not to get “admin” page, just to be able to see pages which are protected for members?

    • Dan

      Create a logout page?

  18. Patricia

    This extension works great! You just need to install :)

    http://wordpress.org/plugins/wp-admin-bar-removal/installation/

  19. Aayushi Jain, how could that possibly have worked?

    I noticed Chris Coyer and Chankey essentially posted the same bit of code, and it is wrong:

    [code redacted, read next comment]
    

    As it stands it is removing the header for users who can’t edit posts, and users who can’t edit posts do not have an admin bar.

    • Sorry it is waaay too late here.

      The incorrect code is:

      add_action('set_current_user', 'csstricks_hide_admin_bar');
      function csstricks_hide_admin_bar() {
        if (!current_user_can('edit_posts')) {
          show_admin_bar(false);
        }
      }
      

      The correct code is:

      add_action('set_current_user', 'csstricks_hide_admin_bar');
      function csstricks_hide_admin_bar() {
        if (current_user_can('edit_posts')) {
          show_admin_bar(false);
        }
      }
      

      The difference is the “!” operator.

  20. Yes. it is very annoying. Thanks for the code. I will surely try this.

  21. Another thanks to Ahmed – I searched high and low for the answer to this – and I hate adding code and messing with stuff like that where a simple 3 second fix like that exists!

  22. This has been so helpful so many times, thanks!

  23. Jay

    How do you hide it only for mobile users with screen size less than 1200px?

  24. Charl

    I have this on my child theme’s functions.php and it doesn’t seem to work. Am I missing something?

    add_action('set_current_user', 'remove_admin_bar');
    
    function remove_admin_bar() {
    	if ( current_user_can( 'manage_options' ) ) {
        	show_admin_bar(false);
    	}
    }
    • Charl, you need to use !current_user_can() This is because the ! means not, at the moment users who can manage options have the bar hidden. Please note that I have not explored the wordpress API

    • Charl

      Thanks! That worked.

  25. How do I remove menu admin bar in wp-admin ?
    Thanks

    • What you need is this:

      function hide_admin() {
      	if (!current_user_can('update_core') || is_admin()) {
      		show_admin_bar(false);
      	}
      }
      add_action('set_current_user', 'hide_admin');
      
  26. Donny

    if you guys don’t want to edit codes, just open new private window (Safari & Firefox) or new incognito window (chrome).

    Then swap between admin window (with wp admin bar) for editing, and guest window (without wp admin bar) to do live testing.

  27. I am using the latest version of WP…and the Nav bar is displayed when you are on the website. You don’t need to signin. I am using a premium theme and I installed buddypress and now I have 2 sets of login/register link displayed on the top left of my screen.

  28. Dan

    its not working anymore in wordpress 4.4, how do i fix it?

  29. Fabrício Batista Rocha

    Thanks!!!

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!