Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Hide the admin bar for non-admins

Hide the WordPress toolbar on the front end for subscribers, customers and every other role except administrators.

  • Type PHP
  • Runs Everywhere
PHP
// Hide the toolbar on the front end for everyone except administrators.
add_filter(
	'show_admin_bar',
	function ( $show ) {
		return current_user_can( 'manage_options' ) ? $show : false;
	}
);

What it does

When users are logged in, WordPress shows a black toolbar at the top of your site. For members, subscribers or customers it just gets in the way.

This snippet hides it on the front end for everyone who can't manage options, which normally means everyone except administrators. The toolbar in the admin area stays.

Good to know

  • To keep the toolbar for editors and authors too, change manage_options to edit_posts.
  • WooCommerce already hides the toolbar for customers, so you may not need this on a shop.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.