How to disable the WordPress Admin Bar

WordPress 3.1 introduces a new feature called the Admin bar. A lot of people will be wanting to disable this when WordPress 3.1 comes out. Since release candiate 2 you can disable it on a per user basis like this:

Disable Admin Bar in user preferences

But since some people might want to disable the admin bar for everyone, I thought I’d show you a couple of ways to quickly disable the WordPress admin bar, either entirely, or just for you, or just for everyone else.

If you haven’t seen it yet, the WP admin bar looks like this, and is added on top of all pages, on both the frontend and backend of your site, when you’re logged in:

WordPress admin bar

Disable Admin Bar for everyone

This one is reasonably simple, to disable the WordPress Admin Bar for everyone, add the following to your theme’s functions.php file, the first bit hides the admin bar, the second bit hides the settings:

/* Disable the Admin Bar. */
add_filter( 'show_admin_bar', '__return_false' );

<?php function yoast_hide_admin_bar_settings() {
?>
	<style type="text/css">
		.show-admin-bar {
			display: none;
		}
	</style>
<?php
}

function yoast_disable_admin_bar() {
    add_filter( 'show_admin_bar', '__return_false' );
    add_action( 'admin_print_scripts-profile.php', 
         'yoast_hide_admin_bar_settings' );
}
add_action( 'init', 'yoast_disable_admin_bar' , 9 );

Disable WordPress Admin Bar for specific requests

You might want to do this for specific requests only, so you can more easily take screenshots, for instance, then you add this to your theme’s functions.php file:

if ( isset($_GET['bar']) && 'no' == $_GET['bar'] )
   add_filter( 'show_admin_bar', '__return_false' );

This would allow you to disable the WordPress admin bar by going to example.com/?bar=no, you can of course change those values.

Disable WP Admin Bar for specific users

To disable the WP Admin Bar, and the Admin Bar preference on his/her profile page for a specific user, add the following to your theme’s functions.php file:

<?php function yoast_hide_admin_bar_settings() {
?>
	<style type="text/css">
		.show-admin-bar {
			display: none;
		}
	</style>
<?php
}

function yoast_disable_admin_bar() {
   if ( 2 == get_current_user_id() ) {
      add_filter( 'show_admin_bar', '__return_false' );
      add_action( 'admin_print_scripts-profile.php', 'yoast_hide_admin_bar_settings' );
   }
}
add_action( 'init', 'yoast_disable_admin_bar' , 9 );

Or you could do the reverse, and enable the WordPress Admin Bar just for one user, by disabling it for everyone else:

<?php function yoast_hide_admin_bar_settings() {
?>
	<style type="text/css">
		.show-admin-bar {
			display: none;
		}
	</style>
<?php
}

function yoast_disable_admin_bar() {
   if ( 2 != get_current_user_id() ) {
      add_filter( 'show_admin_bar', '__return_false' );
      add_action( 'admin_print_scripts-profile.php', 
          'yoast_hide_admin_bar_settings' );
   }
}
add_action( 'init', 'yoast_disable_admin_bar' , 9 );

Update 7-1-2011: post updated after some remarks about current_user not being set yet at the point I was calling it, switched to using the proper __return_false helper function too, using the helpful comment from Cor van Noorloos in the comments.

Update 7-1-2011 – 2: post updated after an API change was decided upon and then implemented.

Yoast.com runs on the Genesis Framework

Genesis theme frameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides you with the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Read our Genesis review or get Genesis now!

27 Responses

  1. CalebBy Caleb on 5 January, 2011

    it can be disabled, at least in 3.1rc2. view your profile, and uncheck the “show admin bar.”

    • CalebBy Caleb on 5 January, 2011

      but definitely useful for killing it all at once or for multiple users

    • Joost de ValkBy Joost de Valk on 7 January, 2011

      Thanks Caleb, added screenshot of the new interface.

  2. CalebBy Caleb on 5 January, 2011

    thank you, yoast!

  3. SwamykantBy Swamykant on 5 January, 2011

    Hi Joost

    I think this similar to wordpress.com. I will check how helpful it for my blog. If not, I will surely use your code.

    Thanks alot.

  4. Cor van NoorloosBy Cor van Noorloos on 5 January, 2011

    Hi Joost,

    Not entirely sure what the most recent way to do this is, but removing the admin bar can also be accomplished by
    add_filter( 'show_admin_bar', '__return_false' );,
    And to remove the user setting
    remove_action( 'personal_options', '_admin_bar_preferences' );

    • Joost de ValkBy Joost de Valk on 7 January, 2011

      Thanks Cor, used your input in my update of the post above :)

  5. KrystianBy Krystian on 5 January, 2011

    Hi Joost,
    AFAIK 3.1. is not released yet, so modification you prosose c an fail to work with the released version. Also option to enable/disable admin bar can be introduced later.

    • Joost de ValkBy Joost de Valk on 5 January, 2011

      I know, and you know what? This is a content management system, if needed, I can just update the post ;)

  6. Bob DunnBy Bob Dunn on 5 January, 2011

    Quick question, if you make this change to your theme’s fuctions.php file, and your theme doesn’t have a custom.funtions.php file, then if you upgrade your theme it will get overwritten, right?

    • Joost de ValkBy Joost de Valk on 5 January, 2011

      Yes.

      • ZenBy Zen on 5 January, 2011

        Wouldn’t a child theme prevent this?

  7. SimonBy Simon on 6 January, 2011

    Not sure why, but I’ve never seen that admin bar in my admin panel. I’ve actually WANTED to see it. Anyone know a reversey-ma-hoo to get the admin bar up there?

    • Joost de ValkBy Joost de Valk on 6 January, 2011

      It’s in WP 3.1 :)

      • SimonBy Simon on 6 January, 2011

        Bah! Just realized I didn’t have it. Thanks :D

  8. StijnBy Stijn on 6 January, 2011

    Funny. I’ve been adding the WordPress Admin Bar by using the plugin with the same name. I find that it makes things much easier to work. It doesn’t look like the example in your screenshot though. I will have to give it a try and see if it’s better; if not, then I’ll surely come back and use this hack to hide it.

  9. Mike DevarenneBy Mike Devarenne on 6 January, 2011

    What would be useful is to disable WP admin bar for user roles.

    Thanks for your many tips Joost!

  10. Dummy00001By Dummy00001 on 7 January, 2011

    I have a WP account now and on bunch of sites the admin bar started showing up.

    What are my option as an user?

    Or annoying blog owners to disable it is the only option?

  11. TheoBy Theo on 7 January, 2011

    Great snippet, thank you Joost!

  12. RamiBy Rami on 9 January, 2011

    What about

    remove_action( 'init', 'wp_admin_bar_init' );

    ?

    • RyanBy Ryan on 11 January, 2011

      When I tried that with WP 3.1 RC2, it got rid of the admin bar, but didn’t remove the gap inserted at the top of the page.

      This admin bar is stupid IMO. It seems to replace the existing menu in the WP admin panel, yet the original one is still there. IMO, WordPress should either use the admin bar only, or just use the standard menu in the left hand side. This combination approach is just weird and I don’t like it one little bit.

      Maybe it will grow on me in time.

  13. James McWhorterBy James McWhorter on 9 January, 2011

    Good stuff, Joost. Bookmarked for future use.

  14. GaryJBy GaryJ on 9 January, 2011

    Since changeset 17234, the second part of your first code snippet won’t work. The user preferences will still be visible, unless you use CSS. Time to update the article again :-)

    • Cor van NoorloosBy Cor van Noorloos on 10 January, 2011

      Hi Gary,

      I’m afraid your right. CSS would do the trick, but somehow I prefer the jQuery way of doing this.

      function cor_personal_options() {
      ?>

      jQuery(document).ready( function() {
      jQuery( "form#your-profile table.form-table tr.show-admin-bar" ).remove();
      } );

      <?php
      }
      add_action( 'personal_options', 'cor_personal_options' );

Trackbacks