2

I don't want users to be able to choose to display the admin bar/toolbar when they log into wordpress. It doesn't have a function for those users.

Instead I would like for admin users to have the toolbar shown by default and anyone else to have the toolbar hidden by default.

I can do this with a plugin by using css and all sorts to hide the toolbar and the option in the profile, however I was wondering if there was a "proper" way to do this at all?

Thanks

3 Answers 3

5

To set the default to not show the admin bar on the public side at registration put the following in your theme's functions.php file (note: this will only work for new users, you'll have to manually disable it for all your current users via the Dashboard):

// Disable the user admin bar on public side on registration
add_action('user_register','trash_public_admin_bar');
function trash_public_admin_bar($user_ID) {
    update_user_meta( $user_ID, 'show_admin_bar_front', 'false' );
}
1
  • I think it would be possible to change the saved settings for all existing users with a single database operation (MySQL or similar).
    – w-sky
    Jan 5, 2022 at 17:38
2

Using the answer by @Matth_eu, you can enable/disable the actual admin bar but to hide the option within the user-edit.php and profile.php screens, use this:

 //Removes the 'Show Toolbar' option.
  function as_remove_personal_options( $subject ) {
    $subject = preg_replace( '#<tr class="show-admin-bar">.+?/tr>#s', '', $subject, 1 );
    return $subject;
  }

  function as_profile_subject_start() {
    ob_start( 'as_remove_personal_options' );
  }

  function as_profile_subject_end() {
    ob_end_flush();
  }
add_action( 'admin_head-profile.php', 'as_profile_subject_start' );
add_action( 'admin_footer-profile.php', 'as_profile_subject_end' );

add_action( 'admin_head-user-edit.php', 'as_profile_subject_start' );
add_action( 'admin_footer-user-edit.php', 'as_profile_subject_end' );
2

Try this - change manage_options to whichever capability you want.

This will show the admin bar only for administrators.

function remove_admin_bar() {

    if( current_user_can( 'manage_options' ) )
        return true;

    return false;

}
add_filter( 'show_admin_bar' , 'remove_admin_bar' );
1
  • Forgot to say - you should add this to your functions.php file
    – Matth_eu
    Feb 22, 2012 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.