Disable WordPress Admin Bar for All Users Except Admins

How to Disable WordPress Admin Bar for All Users Except Admins

in WordPress Admin
Google+ LinkedIn

By default, each registered user has the option of showing the Admin Bar on the frontend and/or back-end of the website. And user can change these preferences, just by visiting Users > Your Profile and choose to show/hide admin bar.

Although it’s nice to have for some users but sometimes you don’t want to allow your users to see the whole top admin bar as there likely isn’t much use in it for them. Therefor here’s a snippet of code which will prevent that toolbar from displaying to all except Admin users.

// disable the wordpress admin bar for all users except admins
if ( !current_user_can( 'manage_options' ) ) {
    add_filter( 'show_admin_bar', '__return_false' );
}

After disabling the Admin Bar, you may want to hide its display settings in each user’s Profile Page too. here is a simple function for that.

// hide admin bar options from user profile page
if ( !current_user_can( 'manage_options' ) ) {
    function wcs_hide_adminbar_options() { ?>
        <style type="text/css">.show-admin-bar { display: none; }</style>
    <?php }
    add_action( 'admin_print_scripts-profile.php', 'wcs_hide_adminbar_options' );
}

Share the love

If you like this snippet, share it with others!

Leave a Reply

Your email address will not be published. Required fields are marked *