There are dozens of reasons to want to hide the WordPress admin bar. Hiding the admin bar is quite easy and can be done with one line of code. This removes the admin bar from everyone even the admins so you may want to conditionally hide the admin from specific users (roles) only.
One common use case is to hide the admin bar from users that don’t need to be able to go to the backend easily like customers in WooCommerce / Easy Digital Downloads.
There are some plugins available that will hide the admin bar for you, but as it is very easy to hide it via a small code snippet it is recommended to do it that way instead of using a plugin.
Hiding the admin bar
To hide the admin bar for everyone you can use the following line of code in your themes functions.php.
Quite easy right? This is the code that will remove the admin bar for every user (including yourself). If that was your intention, awesome! you can now stop reading the rest of this post. If you want to hide the admin bar conditionally, keep reading.
Hiding the admin bar for specific user roles
With the following snippet you can hide the admin bar only from the
author user roles. You can always add extra roles in the same way you’re seeing below.
Or if you only want the administrators to have the admin bar you can also change the code to do just that.
Hide only from certain users
The following snipper can be used to only hide the admin bar from certain users (based on their user ID).
Hiding the admin bar for your user
If you’re somehow not happy with the admin bar in the front end, there’s also a option you can un-check in order to hide the admin bar only from your account without using a code snippet.
Un-ticking the checkbox shown above will make sure that your user won’t show the admin bar in the front end of the site.
3 thoughts on “Hiding the Admin Bar (Conditionally)”
Thank you for this very much…
thanks nice example….^^
great overview. Thanks a lot!