Remove the Admin Bar in WordPress

Note to self.. Seen people talk about it. Seen people hack it. Seen people get crazy about it. The best (and only) way is:

add_filter( 'show_admin_bar', '__return_false' );

And if you’d like only Administrators (or Editors) to see it, but not regular users, with one slight modification:

if ( ! current_user_can( 'edit_posts' ) )
    add_filter( 'show_admin_bar', '__return_false' );

Okay, all this is “my humble opinion”, don’t take me too seriously. Interesting though how the admin bar can break the layout sometimes, especially with WP_DEBUG being switched on, but anyways, I was working on a real estate website last week, and fired the upgrade to WordPress 3.1 and then bam! Well I had to rewrite most of the code anyways since I was upgrading from WordPress 3.0-beta1. Seriously!

So I fixed my rewrites, my custom JOINs (by the way meta_query seems to now work just as fast as custom SQL JOINs when the meta table is indexed correctly), and my custom taxonomies. I saw the admin bar, I liked it, but hey, I’ve got a cool sign up and login forms there, with social logins as well, so it wouldn’t be very nice if the WordPress admin bar popped out to somebody looking to buy an expensive villa in Italy or Monaco ;)

So yah, use the code above in your functions.php file to get rid of the admin bar, others (through actions) tend to forget to remove some stylesheet or markup. Cheers!

About the author

Konstantin Kovshenin

WordPress Core Contributor, ex-Automattician, public speaker and consultant, enjoying life in Moscow. I blog about tech, WordPress and DevOps.

3 comments