How to hide WordPress admin bar with code

Open your theme’s function.php file. Add the following code at the end of your functions.php file.

In the example below, the admin bar will only appear when the logged in user has role of “administrator”.

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

Leave a Comment

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

13 + = 15