There are many WordPress sites that have end users who have no need to see the WordPress admin toolbar. You know, that black bar that shows up at the top of the site when you’re logged in. It is extremely useful for admin users to be able to quickly jump between front end pages and the back end pages of the site. For typical end users, the bar can be confusing and (possibly) provide access to areas of your site that you don’t want them to access. This tutorial will show you how to remove the admin toolbar in WordPress.
Easy Approach
This approach is for if your site only has a handful of users who shouldn’t see that toolbar. In each user’s profile page in the admin area, there is a setting that asks if the site should show the toolbar when viewing the site.
Simply uncheck that box for each user and save their settings.
Again, this approach is only useful if you only have a handful of users and the site won’t get many more users in the future. You obviously don’t want to be running an e-commerce site and have to constantly go to each new customer’s profile to remove this setting.
Remove the Admin Toolbar in WordPress with Code
If you know that you only want site administrators to be able to view the admin toolbar in WordPress, it might be easier to remove it with code.
<?php add_action( 'show_admin_bar', 'sd_remove_admin_toolbar' ); function sd_remove_admin_toolbar(){ $show = true; if( !current_user_can( 'manage_options' ) ){ $show = false; } return $show; } |
The current_user_can
function checks whether or not the current, logged in user has the capability to manage_options
. This is a standard capability of administrators on your site.
With the !
before that function, we’re telling our code to check to see if the current logged in user does not have the capability listed. This would be true for all users lower than administrators, since Editors, Authors, Contributors, and Subscribers do not have the manage_options
capability.
If you want to show the admin toolbar in WordPress to users with other roles, you would simply replace manage_options
with an appropriate capability from this list.
Now whenever a user logs into your site from a front-end login form, they will never be shown the admin toolbar in WordPress.
Were does the code go? I assume it’s in functions.php, however it’s not clarified in your article.
Yes, functions.php will work, or you can create a separate plugin for it if you wanted to. This could avoid losing the code on theme updates, unless you’re using a child theme, which you should be doing anyway 🙂