Disable WordPress Admin Bar for All Users Except Admins

[ad_1]

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' );
}
[ad_2]

Leave a Reply

Random Post Selection ::

Recent Posts

Unlock Unlimited Downloads