Remove WordPress Admin Bar Except For Administrator

You have given the capability of registering in your site for the users who visits in your site. But, you want to remove WordPress admin bar for those users who visits your site and then registers in your site for any purpose. So, what to do in this condition? Do you really need a plugin for this at all in your site? Well, we would like to say that, the use of the plugin for this purpose in your site depends on your requirement as how you want them to be treated in your site.

When we will use the plugin for this? Well, its simple, if you want to display that bar, WordPress admin bar for the custom users registered in your site, then, the use of the plugin for this purpose would be of great use for your site. But, if you do not want to display it at all for all of the users, except for the administrator, ie, the main site owner of the site, then, the use of the plugin for this purpose is really not required in your site. Here, we will provide the code to remove WordPress admin bar from the users who are registered in your site, but is not the administrator of the site. The code for this is given below as:

add_action('after_setup_theme', 'theme_slug_remove_admin_bar');
function theme_slug_remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {

Well, now you may want to know about how and where to use this code in your site, right? Well, you can just copy and paste the above provided code in the child theme’s functions.php file, if you have already created it in your site. But, if you do not have it already installed in your site, then, you can follow this tutorial to create the WordPress child theme for your site and use it in your site.

Here, the below provided screenshot is when we have not created the WordPress child theme and added the above provided code at all in any of the theme file:


Now, after we have applied the above code provided to you, in our local development environment, we can see out the browser screen of our while we are logged in to the site, with the lower privilege than the administrator as the screenshot below:


Here, in the above screenshot, we can clearly see that the code provided above written in the functions.php file of the child theme has removed the display of the WordPress admin bar from your site when the user with no administrative role are logged in to your site. So, since now you have learned about how to remove WordPress admin bar for your site from here, its time for you to utilize it properly in your site.

Post navigation

Bishal Napit

Bishal Napit is a WordPress theme developer from Tansen, Palpa, with a passion to learn more on WordPress.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.