info@martej.com
One-Stop Developer Agency

How to hide default WP admin bar using PHP

Last update: 19/04/2023

In this short tutorial we will check how to hide default WordPress admin bar, that is visible at the top of the page when user is logged in.

Default admin bar

In the code snippet plugin or functions.php you just insert following code and it will work:

<?php 

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

For example, in the example above we will hide the admin bar for all users that are not administrators. If we want to hide also for administrators (which I don’t recommend), then we simply remove if statement.

I hope this short tutorial solves helps you 🙂

Leave the first comment