Hide the admin bar in WordPress – .com

In this tutorial we are going to see how to hide the WordPress admin bar from a specific user, a specific role or all identified users.

WordPress admin bar

The WordPress administration bar is displayed by default to any user who logs into our website. This can be quite useful as it allows us to quickly access some of the WordPress dashboard options while we are browsing the page.

But it is also true that other times it can be a bit annoying, for example if we are in the development stage of the web.

In that case we could prefer to hide it and thus view the site as any user would see it, without that extra. So let’s see how we can hide said bar as we wish. We will see how to do it from the WordPress panel itself, with code and also with CSS. Let’s go there!.

Hide admin bar for a specific user

To do this we have to go to the WordPress desktop, “Users”, and access the profile of the user that interests us by clicking on “Edit”.

We will see that there are several options available, and one of them is precisely the one that allows us to change the visibility of the toolbar / administration. We will simply have to uncheck “Show the toolbar when viewing the site”, and save the changes by clicking on “Update profile”.

In this way, the user that we have selected will no longer see the administration bar when he is identified on the site, we are talking of course about the frontend bar, not the one that corresponds to the WordPress desktop.

This can be done both by the users themselves from the “Profile” menu option that will appear once they are identified on the page, and by the administrators of the site.

As you can see, it’s easy to do it when it comes to a specific user, but what if we want to hide the toolbar from all subscribers? What if we want to do it with another specific role? We will see it in the next point.

See also  Social media course #10. Audience Insight - .com

Hide admin bar to a specific role

The easiest way to hide the WordPress toolbar to a specific role is through code. If you don’t handle the subject very well, you can take a look at , where in addition to beginning the journey towards WordPress development, you will learn the best programming practices for this CMS.

Well, as we have said, we are going to add a few lines of code so that we can hide the admin bar from all users who have a specific role. In this case we will give an example with the subscriber role, but it could be any other.

As we have seen on other occasions, we can add this code in various ways as we explained in the tutorial for . In short, we could insert it in the functions.php file of the theme that we have active, also in a snippet using the Code Snippets plugin, or even in a utility plugin that we have previously created.

This last way is the one that we recommend and the one that we are going to carry out in this case since with this method if we change the theme or, for whatever reason, the template is updated, we do not lose the functionalities that we have programmed.

So we advise you to create a utility plugin and add there the lines of code that you need. Well, having said all this, we are going to access it from the FTP program that we use and, with it deactivated, we will include the following code. Then we will have to save the changes, and reactivate the plugin from the WordPress dashboard for them to take effect.

See also  WordPress security course - .com

//Hide admin bar from all subscribers add_action(‘after_setup_theme’, ‘bld_hide_admin_bar’); function bld_hide_admin_bar() { if (current_user_can(‘subscriber‘)) { add_filter( ‘show_admin_bar’, ‘__return_false’ ); } }

As we can see, the first thing we do is include the “bld_hide_admin_bar” custom function in the “after_setup_theme” action hook that is executed just after configuring the theme.

Next we define said function and, within it, we check if the current user is a subscriber, in which case we modify the visibility of the admin bar and hide it. By the way, where it says “add_filter( ‘show_admin_bar’, ‘__return_false’ );”, we could also have written “show_admin_bar(false);”.

You see that it is quite simple, and we could do the same with other roles. If we wanted to hide the toolbar from all administrators, we would simply have to replace “subscriber” with “administrator” in the code, the same for the rest.

Hide admin bar from all users

Well, we have seen how to hide the front-end admin bar from specific users and a set of users with a specific role. What can we do if we want to hide it from all users?

In such a case there would be at least a couple of possible options. The first could also be with code, can you guess how?

If you have been attentive to the lines included above, you will have noticed that within the function we are checking if the user is a subscriber and, only when it is so, we hide the bar.

Keeping this idea in mind, it will be easy for you to imagine what would be the solution to hide the toolbar from all users regardless of their role.

//Hide admin bar from all users add_action(‘after_setup_theme’, ‘bld_hide_admin_bar’); function bld_hide_admin_bar() { add_filter( ‘show_admin_bar’, ‘__return_false’ ); }

Yes, exactly. All we would have to do is remove the condition. This way any user who logs into our site will not see the admin bar. But this is not the only way, let’s see one more. It is not as recommended as using PHP code, but we leave it here in case you do not know it.

See also  Web layout techniques course #7. Tabs or tabs - .com

We are talking about hiding the toolbar using CSS. To do this, we would have to make a small change in the style sheet of the child theme that we have active in WordPress, or it would also be useful to include the code in the theme customizer, in “Appearance/Customize/Additional CSS”, and publish the changes. It would be only three lines:

#wpadminbar { display: none; }

And that’s all! You already see that hiding the admin bar in WordPress is very simple, surely at some point it will be practical for you.

Summary and conclusion

As we have seen, we can hide the toolbar from a specific user by making a small adjustment in their profile, which we can access from the WordPress desktop. If we are interested, we can also change the visibility of said bar to users who have a specific role, we have seen this using code.

You already know that through programming we can do whatever we want, so if you are interested in learning we recommend the one or the one from . Finally, if we want to hide the admin bar from all users, regardless of their role, we can do it by code or through CSS.

And that’s all! We hope you have found it useful. As always we recommend the . If you subscribe you will have access to the PHP course we just mentioned, as well as more than 6047 videos about WordPress, development, and many other topics 🙂

Loading Facebook Comments ...
Loading Disqus Comments ...