Hide the admin bar for non-admins
Hide the WordPress toolbar on the front end for subscribers, customers and every other role except administrators.
// 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_optionstoedit_posts. - WooCommerce already hides the toolbar for customers, so you may not need this on a shop.