Remove WordPress Admin Bar for non-Admin Users

Rezumat

To remove the WordPress admin bar for users who are not Administrators, add the following code to your functions.php file.

add_action('after_setup_theme', 'remove_admin_bar');
	function remove_admin_bar() {
	if (!current_user_can('administrator') && !is_admin()) {
	  add_filter( 'show_admin_bar', '__return_false', 99 );
	}
}

To remove the WordPress admin bar for users who are not Administrators, except for a specific user role, use the code below.

add_action('after_setup_theme', 'remove_admin_bar');
	function remove_admin_bar() {
	if (!current_user_can('administrator') && !current_user_can('user_role_222') && !is_admin()) {
	  add_filter( 'show_admin_bar', '__return_false', 99 );
	}
}

Replace user_role_222.