You might want open registration on your WordPress site so that (for one small example) people can log in and leave comments on things without needing to type their name/url/email every time. But these users probably don’t need to see the whole top admin bar as there likely isn’t much use in it for them. Although do be sure to provide a link to edit their profile and log out.
This would be for your functions.php file or functionality plugin:
add_action('set_current_user', 'cc_hide_admin_bar');
function cc_hide_admin_bar() {
if (!current_user_can('edit_posts')) {
show_admin_bar(false);
}
}
Didn’t work for me. It still shows up for all users. Is it a problem with the set_current_user hook? I ended up using on of the options in this article: http://digwp.com/2011/04/admin-bar-tricks/#disable-for-non-admins.
No need for code. Very easy and simple plugin for it. It’s called user front end plugin.
Hiya, just wanted to let you know your code works fine in 3.5.1 Admin bar shows up for admins, but not normal subscriber level users.
I couldn’t get it to work. set_current_user is a depreciated function. I hooked it to wp_footer instead and it did the trick. Although, it’s still adding 28px padding to the top of the html tag.
This piece of code doesn’t use the function set_current_user which is deprecated as you say, rather it uses the action hook called set_current_user which is still current, https://developer.wordpress.org/reference/hooks/set_current_user/ btw, the snippet worked perfectly for me on 23.4.18 — thanks!
i’m using S2 member plugin, can i use this code in function.php…?
I got it to work for me. Thanks a ton.
Finally got it. The Admin WP bar is removed. Good article.
Just type in wp-content/themes/mytheme/functions.php the following:
show_admin_bar(false);
Swap mytheme for the name of your theme’s folder.
Worked perfectly, placed in my child functions.php
Worked on desktop, not on an iPad Air 2 though.
Thank you, this worked. :-)
Above solution did not work for me I am using WordPress version 5.8.2
Instead below code snippet worked:
if(!current_user_can(‘edit_posts’)){
add_filter(‘show_admin_bar’,’__return_false’);
}
I always felt like the WP admin bar takes too much attention and was a fan of hiding it. Eventually, I came to editing the CSS and found this solution:
https://romangr.com/blog/wp-admin-bar
It doesn’t hide the bar itself but makes it almost unnoticeable yet accessible.