There are numerous plugins that offer this functionality. For example, the User Role Editor plugin has an option to hide the admin bar for each user role. If, however, you want a quick solution to implement this in your code without the need for installing a plugin, here’s how you can do that.
/* Hide admin bar for everyone except admins */
function myprefix_remove_admin_bar() {
if (!current_user_can('administrator') !is_admin()) {
show_admin_bar(false);
}
}
add_action('after_setup_theme', 'myprefix_remove_admin_bar');
This snippet only applies to non-admin pages. If a user has access to the back-end it will still show the admin bar on those pages. The is_admin() function is used to determine if the current page is an admin page or not.