Post Pic

WordPress tip: Show admin bar only for admins

Introduced in WordPress 3.3, the admin bar is a new version of the controversial “Toolbar” which came with WordPress 3.0. Personally, I think the admin bar is useful only when you’re the blog admin. When you’re a simple contributor, you don’t really need it. So why not getting rid of it, except for admins?

Simply paste the following code into your functions.php file. Once saved, only admins will see the admin bar.

if (!current_user_can('manage_options')) {
	add_filter('show_admin_bar', '__return_false');
}

Thanks to Jeff Starr for the tip!

Related Posts

No related posts.

4 Responses

Jan 18 2012 00:56

If you’d rather put this in a functionality plugin instead of a theme (http://www.doitwithwp.com/create-functions-plugin/), you’ll probably have to put it inside a hook like template_redirect. Otherwise it’ll run too early and the user data won’t be available to current_user_can().

Jan 19 2012 09:33

How can the user log out if no admin bar displays?

Jan 21 2012 10:39

@ schiwe

they can always go to the dashboard and logout or you can place a logout link in the blogroll.

Feb 01 2012 11:31

If you decide to remove the admin bar then to provide your website visitors with a way to logout you can use the code:

echo wp_logout_url( $redirect );

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required