how to remove admin bar for non admin users in wordpress

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.

ReadyMadeCode
Author: ReadyMadeCode

ReadyMadeCode.com is a website where you can find Free Online Tutorials - Website Development Tutorials, App Development Tutorials, Coding Tutorials,Website Designing and Development From popular programming languages or scripts or framework like php, laravel, html, css, javascript, nodejs, java, angularjs etc. Download Emails | E-Books.

View All Posts From ReadyMadeCode
Author Website : https://www.readymadecode.com
Scroll to top

Subscribe For Latest Updates

Enter your email address to subscribe and receive notifications of posts & updates by email.


Want a Website / App / Digital Marketing Solution

Website & App Development Packages

%d bloggers like this:
We have updated our memberships. Please check here
Close X