When you log into your WordPress website, the WordPress admin toolbar will be displayed at the top of your site. This toolbar is used when accessing quick links to manage your site or when switching between the front-end and back-end of your website. Its not always needed though and if you have a website where people log in to view content on the front-end, you may want to disable showing the admin toolbar to these users.
In this guide we will be disabling the admin toolbar through settings and also site-wide using code.
The WordPress admin toolbar is displayed on the front-end and on the back-end of your site when you are logged in.
It is, however, not always wanted and can sometimes hinder the user experience. This is especially the case when you only want users to log into your site and view pages on the front-end. If the admin toolbar is present, it will display a link to view the back-end. That is why you can hide it to prevent the user from viewing the back-end of your site.
Often the toolbar can get in the way of some WordPress themes and other times you simply do not want it to be there.
Fortunately there is an easy fix!
The flexibility of disabling the admin toolbar is great. There are a number of options you can use to customize exactly how you want to hide the toolbar.
Disable the admin toolbar in profile settings
If you want to disable the admin toolbar when you are viewing your website for yourself then you can do so in your profile settings.
[highlight type=”note”]This method will turn off the admin toolbar only when you are logged in but it does not disable it for every other user. If your intention is to remove the toolbar for every user that logs in then you can do so with the next method.[/highlight]
Go to your profile settings by either hovering over your name in the top right hand side of the admin toolbar and selecting Edit My Profile.
Or access your profile settings by going to Users > Your Profile in the admin sidebar. Either way, it will take you to the same profile edit page.
On this page, uncheck the Show Toolbar when viewing site checkbox and then click the Update profile button.
Your admin toolbar will now be hidden when you are viewing the front-end of your website. That is all you need to do to disable the WordPress admin toolbar on the front-end. WordPress used to allow you to disable the toolbar in the back-end of your website but have since disabled that function.
If you would prefer to disable the admin toolbar by using code, in the next step we will disable it for all users.
Disable the admin toolbar site-wide for all users using code
When you want to disable the admin bar for all users, you need to overwrite the settings by using code.
The following code gets put into your child themes functions.php file.
[code type=”php”]// Disable WordPress admin toolbar for all users on the front-end
add_filter( ‘show_admin_bar’, ‘__return_false’ );[/code]
The above code adds a filter to tell WordPress to disable the admin bar for all users when they are logged in and viewing the front-end of your website.
This function can be modified to show the admin toolbar for certain user levels and hide it for other user levels. For example if you are the website administrator then you may want to keep the toolbar but for your subscribers, you want to hide the WordPress admin toolbar.
You can do this by putting the following code into your child themes functions.php file.
[code type=”php”]// Disable admin toolbar for all users except administrators on the front-end
function wpabsolute_hide_admin_bar($content) {
// Returns true if user is administrator, otherwise false.
return ( current_user_can( ‘administrator’ ) ) ? $content : false;
}
add_filter( ‘show_admin_bar’ , ‘wpabsolute_hide_admin_bar’);[/code]
The above code checks if you are an administrator and if you are, it will display the admin toolbar and if not it will hide it.
You can change the level of user access required to view the toolbar by changing the “administrator” value in the current_user_can function to something else. For example, if you want to show the toolbar to administrators and editor then you can use the capability of “edit_pages”. This will enable the toolbar for administrators and Editors but disable for all other users. The updated code would look like this:
[code type=”php”]// Disable admin toolbar for all users except administrators and editors on the frontend
function wpabsolute_hide_admin_bar($content) {
// Returns true if user is administrator or editor, otherwise false.
return ( current_user_can( ‘edit_pages’ ) ) ? $content : false;
}
add_filter( ‘show_admin_bar’ , ‘wpabsolute_hide_admin_bar’);[/code]
You can view a full list of available roles and capabilities on the WordPress Codex.
This tutorial gave you insight into how to disable the WordPress admin tool on the front-end of your website.
Even though you have disabled the admin bar, users that have logged in can still have access to view the dashboard or back-end of you website. Make sure you are disabling access to the admin dashboard too.
If you are building a membership style website then you can create your own custom login pages too.
Did this tutorial help you? Let us know in the comments below if there is anything more you would like to know on customizing your WordPress website.
Thank you for the code. However, I’m quite certain that I shouldn’t be using “function wpabsolute_hide_admin_bar($content)” … because wpabsolute is your website; not mine. It is hard to put into words how demoralizing it is to search and search and search for info, while simultaneously being 100% certain that what I’m reading is incorrect. Maybe all I need to do is replace that with my website… but, I am guessing. Furthermore, if that is incorrect, how could I possibly know what else is. Everything is suspect now.
Hi Rick, “function wpabsolute_hide_admin_bar” is just the name of the function. Its not used solely for this website. Think of it like a name tag that is used to identify the code that is run inside the function.
The best way to learn is to try it and see if it works for you. I would also suggest if you’re interested to learn the basics of PHP as that will help you to understand what the code does.
All of these functions have been made so that anyone on any site can use them.
Oh. Thank you for your quick reply. So, just to clarify, that isn’t your website name in the function? But rather, your website got its name from the PHP function? Therefore, just copy/paste what you have? Thanks again for your time
It is the name but it doesn’t correspond to my website – its just the name so you can copy the code letter for letter and it will work on your site.
If you’d prefer, you can replace all references of wpabsolute to your websites name or anything else but is not necessary. Think of it as a way to search for where that function came from if you look at that code a year down the track and need to revisit it. If its unique then you might not be able to track it down.
Its used as a prefix so as to not conflict with any other function you might already have on your website already. Just make sure it follows the same conventions (lowercase, no spaces etc.)
Ahh! Very helpful. I think I need to take your advice and learn PHP. Much appreciated!
Hello! Can you please tell me how to modify the code snippet to allow Administrators + Editors to see the Admin bar on the front-end? Thanks for all your help.