Show admin bar only for some USERS roles

You can disable the admin bar via function:

show_admin_bar(false);

So with that in mind, we can hook into after_setup_theme and hide the admin bar for all users except administrator and contributor:

function cc_wpse_278096_disable_admin_bar() {
   if (current_user_can('administrator') || current_user_can('contributor') ) {
     // user can view admin bar
     show_admin_bar(true); // this line isn't essentially needed by default...
   } else {
     // hide admin bar
     show_admin_bar(false);
   }
}
add_action('after_setup_theme', 'cc_wpse_278096_disable_admin_bar');

I am only using administrator and contributor as example. You can of course change this and add more roles.

Leave a Comment