Hide admin bar to non logged in users

Sometimes on some hosts even after logout from WordPress admin, the admin bar is still showing up on the front-end. To hide it, you can use one of the methods described below.

Disable Admin Bar for All Users Except Admins with a Plugin

This method allows you to quickly disable the WordPress admin for all users.

Install and activate the Hide Admin Bar Based on User Roles plugin. Upon activation, go to the Settings » Hide Admin Bar Settings page. From here, check the boxes next to the user roles where you want to disable the admin bar.

Don’t forget to click on the ‘Save Changes’ button to store your settings.

Disable Admin Bar for All Users Except Administrators Using Code

This method requires you to add code to your WordPress theme files. Simply add the following code to your theme’s functions.php file or a site-specific plugin.

if (!function_exists('remove_admin_bar')) {
  add_action('after_setup_theme', 'remove_admin_bar');
  function remove_admin_bar() {
    if (!current_user_can('administrator') && !is_admin()) {
      show_admin_bar(false);
    }
  }
}

This code checks if the current user is not an administrator, and they are not viewing the admin dashboard. If both conditions match, then it will disable the WordPress admin bar.

Don’t forget to save your changes and check your website to make sure everything is working fine.

Disable Admin Bar for All Users Including Admins

What if you wanted to disable the admin bar for all users including yourself and any other administrator on your site? You can do this by modifying the code we showed earlier.

Simply add the following code to your theme’s functions.php file or a site-specific plugin.

/* Disable WordPress Admin Bar for all users */
add_filter( 'show_admin_bar', '__return_false' );

This code will disable the admin bar for all users when viewing the public pages of your website. All users will still be able to see the toolbar inside the WordPress admin dashboard.

Was this page helpful?