Remove the admin bar for logged in users

Code snippets should be placed in your functions.php file or extracted in to your own custom plugin.

Hide for all users

Removing the admin bar for all users is very simple. Hook in to show_admin_bar and return a true or false boolean value:

add_filter('show_admin_bar', '__return_false');

Hide for all users except Administrators and Editors

To optionally hide the admin bar, just wrap the filter above in a conditional statement. Below we check if the current user can edit posts, and if so, we assume they are an Editor, or Administrator.

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

Hide for all users except Administrators

Similar to the above, except we check if the user can manage options, instead of edit posts.

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

If you’re wondering why __return_false and not the regular method of returning a value from a function – WordPress has a few useful utility functions to quickly return values to filter hooks. It’s used in situations where a callable function needs to return false.

So this:
add_filter('random_wp_filter', '__return_false');

Instead of:
add_filter('random_wp_filter', function(){return false;});

@wpthemedotdev Post