Contact information
Follow us
How to hide WordPress admin bar

WordPress admin bar is a toolbar shown at the top. When we already logged in at WordPress backend and browse the frontend then it will appear at the top. This tool bar provides various helpful options which allow us to go directly at admin area and manage required things easily. For example we are viewing any page on frontend and we need to edit the page then with the help of tool bar we can do it very quickly by just clicking on “Edit Page” link instead of going to backend – page list and then edit the page.

But sometimes we need to get rid of it when it comes in our way. Specially when we are working on design, or we need to see a quick preview that how the page is looking without that toolbar. Thus we need to hide WordPress admin bar.

It can be super easy with single WordPress site by just checking/unchecking a checkbox. But what if multi-site WordPress installed then that check-box will hide WordPress admin bar for all the sites and we just need to hide WordPress admin bar on the site we are working on. Therefore we need to add some functions which enables us to hide WordPress admin bar for current site only.

Following are few ways which allow hiding admin bar based on requirements. We need to place this hooks in functions.php file.

Hide WordPress admin bar for some sites on multi-site network

1. For one site

add_action('after_setup_theme','remove_admin_bar_for_one_site' );
function remove_admin_bar_for_one_site() {
   // the global variable
   global $blog_id;
   // remove admin bar for any one site
   if ($blog_id == 1){
      show_admin_bar(false);
   }
}

2. For multiple site

add_action('after_setup_theme','remove_admin_bar_for_multiple_site' );
function remove_admin_bar_for_multiple_site() {
   // the global variable
   global $blog_id;
   // remove the admin bar from multiple sites
   if (in_array($blog_id, array(1,2,4,5,10,15))){
      show_admin_bar(false);
   }
}

Hide WordPress admin bar for one page only

// hide the admin bar for home page
add_action('after_setup_theme', 'remove_admin_bar_for_homepage');
function remove_admin_bar_for_homepage() {
   if (is_home()){
      show_admin_bar(false);
   }
}
// hide the admin bar for any other page
add_action('after_setup_theme', 'remove_admin_bar_for_a_page');
function remove_admin_bar_for_a_page() {
   if (is_page('About Us')){
      show_admin_bar(false);
   }
}

Hide WordPress admin bar based on user access rights

add_action('after_setup_theme', 'remove_admin_bar_userwise');
function remove_admin_bar_userwise() {
   // check for permissions and hide admin bar
   if (!current_user_can('read')){
      show_admin_bar( false );
   }
}

Always hide WordPress admin bar

add_action('after_setup_theme', 'remove_admin_bar_always' );
function remove_admin_bar_always() {
   show_admin_bar(false);
}

You can also add filter to hide WordPress admin bar

add_filter('show_admin_bar', '__return_false');

Furthermore, there’s obviously a wide variety of scenarios for when and where to hide your admin bar, but hopefully the above examples will give you a good groundwork. This code will, most likely, go in your functions.php file.

Above code segments are few scenarios to hide WordPress admin bar. Examples shown above can be really helpful. Therefore, if you’ve any suggestions/comments then please add your comments or reach me from here https://freelancer-coder.com/contact/.

Probably useful resources:

Leave a Reply

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

Transform your vision into reality!

Let's start building your dream website now.

Get a Free Quote