How to remove admin bar for non admin users in wordpress

In this article we will teach you how to remove admin bar for non admin users in wordpress and also for specific users and for all users.

Now To remove admin bar for non admin users, paste this code in your functions.php file located at rote_directory_path/wp-content/themes/your_theme/functions.php

add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar() {
	if (!current_user_can('administrator') && !is_admin()) {
		show_admin_bar(false);
	}
}

And paste this code in your functions.php file located at rote_directory_path/wp-content/themes/your_theme/functions.php

add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar() {
	show_admin_bar(false);
}

If you want to remove admin bar for shop manager in your woocommerce website. Then paste this code in your functions.php file located at rote_directory_path/wp-content/themes/your_theme/functions.php

add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar() {
	if ( isset( $user['roles'][0] ) && $user['roles'][0] == 'shop_manager' ) {
		show_admin_bar(false);
	}
}

If you want to remove admin bar for other users roles. Then here below is trick which you can use to identify the user roles and if condition in remove_admin_bar() function. Here $user_roles is an array having all roles values of wordpress users. And in $user_roles you can find your desired roles and can apply condition to your desired roles.

$user = wp_get_current_user();
$user_roles = (array) $user->roles;
if ( in_array( 'author', $user_roles ) ) {
    //The user has the "author" role
}

That’s it Now you have learned the trick how to remove admin bar for non admin users in wordpress. By using this code you can remove admin bar for other type of users.

And if you want more tutorials and tricks about wordpress then visit our WordPress Page. And follow us on facebooktwittertumblrlinkdedin and if you like this article then share this.