I am using a function to hide the WP admin bar for specific users with the following code:
//Hide admin bar for subscribers
if (current_user_can('subscriber') || !is_user_logged_in() ) {
// user can't view admin bar
show_admin_bar(false);
}
else {
show_admin_bar(true);
}
It works for subscribers
and visitors
but when logged in as an administrator
the admin bar doesn't show up on the front-end. Can anyone tell me what I'm doing wrong?
SOLUTION: The code above here works
Try,
//Hide admin bar for subscribers
if( current_user_can('subscriber') || current_user_can('visitor') ) {
// user can't view admin bar
show_admin_bar(false);
} else {
show_admin_bar(true);
}
Updated Code:
//Hide admin bar for all users except administrators
if( current_user_can('manage_options') ) {
show_admin_bar(true);
} else {
// All other users can't view admin bar
show_admin_bar(false);
}