Skip to content

Instantly share code, notes, and snippets.

@gerardreches
Last active March 2, 2022 15:39
Show Gist options
  • Save gerardreches/c86fa8e6062d40fa986db7c511653ca4 to your computer and use it in GitHub Desktop.
Save gerardreches/c86fa8e6062d40fa986db7c511653ca4 to your computer and use it in GitHub Desktop.
Hide WordPress admin bar for specific roles
function disable_admin_bar_for_roles() {
// Add here the roles you want to not have admin bar.
$excluded_roles = [ 'subscriber' ];
return is_user_logged_in() && ! array_intersect( wp_get_current_user()->roles, $excluded_roles);
}
add_filter('show_admin_bar', 'disable_admin_bar_for_roles');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment