How to disable the WordPress admin bar for logged-in users, except admin
-
I have installed WP-Members. I have also turned off “anyone can register”. During testing, when logged in as a member, I see a black strip at the top of the page which is a wordpress user bar, which I don’t want to appear. There are no options anywhere for turning that off, either in wordpress or in wp-members.
Looking around for answers I found this page:
https://www.butlerblog.com/2011/09/23/how-to-disable-the-wordpress-admin-bar/
suggesting adding some code to the functions.php file:“If you would like to keep the admin bar for yourself, you just need to add a condition to test to see if the current user is an admin. This example tests if the user has the capability to ‘manage_options’. (If you have a role manager installed and have made changes to the default WP roles, adjust this accordingly.)
if ( ! current_user_can('manage_options') ) { add_filter( 'show_admin_bar', '__return_false' ); }
This can be used regardless of whether you are using the WP-Members plugin or not, but if you are using the plugin, this will prevent your subscribers fromhaving the admin bar appear for them when they are logged in“
It sounds like a simple fix, yet I am hesitant in case it doesn’t work as I expect and instead actually bars me from the admin panel, which would make me unable to get into my wordpress admin anymore.
In the User section, I have set my role as “Administrator”. So in theory, I shouldn’t get blocked from seeing the top bar, however I can’t be certain about the code, as that is not my area of knowledge. It refers to “role manager” and “manage_options”, which doesn’t seem to exist in the admin panel, although I see there are plugins for role managers, yet I am hoping I don’t have to add yet another plugin – unless necessary. I am wondering if setting myself as admin in the users area is enough, and whether the above suggested code would work in the functions.php file to stop logged-in members from seeing the bar, except for me as admin of course.
Otherwise, I wonder if there is another idea or workaround?
- The topic ‘How to disable the WordPress admin bar for logged-in users, except admin’ is closed to new replies.