How do I turn off the Admin Bar for all Subscribers?

Maybe this is a stupid question.

When a user logins to my WordPress site with the Subscriber role, they have the WP Admin Bar appearing at the top of the page. The user can go into their dashboard and turn this off themselves. But how can I turn this off by default for all existing and new users?

Related posts

Leave a Reply

1 comment

  1. function disable_admin_bar_for_subscribers(){
        if ( is_user_logged_in() ):
            global $current_user;
            if( !empty( $current_user->caps['subscriber'] ) ):
                add_filter('show_admin_bar', '__return_false');
            endif;
        endif;
    }
    add_action('init', 'disable_admin_bar_for_subscribers', 9);