How to fix the WordPress Admin Bar showing when logged out

You've just logged out of WordPress, but the admin bar is still showing. I'll show you how to resolve the problem in 2 minutes.

Web Development Menu

So, you have just logged out of your WordPress dashboard, but to your surprise, the admin bar is still there. You log in, and out again, but the admin bar is still there. First of all, don’t panic. There is a simple explanation.

Let me calm your fears:

  • Your admin area is safe - The public cannot access it. All they see is the bar itself, but none of the links on it will work.
  • It’s easy to fix - In just two minutes I will help you solve your problem. I promise.

I am aware of two different culprits; W3 Total Cache, and CloudFlare full page cache.

W3 Total Cache Page Cache

WordPress by default will query a database and run PHP every time a page is requested. In essence, it builds the page every time a visitor lands on it.

W3 Total Cache takes that finished version of the page, and stores the final output of the page in the cache. Then when a subsequent visitor lands on the page, the page is loaded from the cache, rather than built on demand.

This significantly speeds up the render time of your webpage as well as reducing the load on the web server, and I would highly recommend adding caching to your website. You can view our guide on how to set up W3 Total Cache properly here, or follow this more up-to-date version that is specific to A2 Hosting.

The problem you face is because you have misconfigured W3 Total Cache. You have set it to cache pages for logged in users. By doing this, you are caching the entire page, including the admin bar.

When logged out, you are only seeing a cached version of the Admin Bar. Because a user is not logged in, they will get an authentication error when they try to visit any of the admin area links. Your site is, and always has been safe from this issue.

Fixing the problem in W3 Total Cache

The solution is straightforward. Let me show you.

How to fix the WordPress admin bar from being shown when logged out by W3 Total Cache.
  1. Navigate to Page Cache Settings
    In the WordPress Admin sidebar, click “Performance,” and then click “Page Cache” to navigate to the Page Cache Settings in W3 Total Cache
  2. Tick the box that says ‘Don’t cache pages for logged in users’
    Tick the box that says “Don’t cache pages for logged in users,” as shown in the screenshot (click for a larger version).
    Tick the box that says 'Don't cache pages for logged in users'
  3. Click ‘Save all Settings’
    Click “Save all Settings.”
  4. Clear your Page Cache
    Once you have cleared the page cache, the Admin bar will no longer show to users that are not logged in.

CloudFlare Page Cache

If you configure a rule in CloudFlare to cache the entire HTML page, and then visit your WordPress site while logged in, that page will be cached in its entirety by CloudFlare. This includes any admin bar.

You can easily test that this is the problem, by clearing the CloudFlare cache and visiting the page while logged out. You may need to clear the browser cache by pressing [CTRL] [F5]. If the admin bar disappears, the problem is caused by CloudFlare.

Fixing the problem caused by CloudFlare

While this solution is specifically geared towards CloudFlare users, it will also fix the problem caused by any other caching plugin or caching service, including W3 Total Cache.

How to fix the WordPress admin bar from being shown when logged out with CloudFlare Page Cache.
  1. Go to the Theme Editor and load functions.php
    Under the Appearance section, click the Editor Option. Then on the right hand side, click the Theme Functions (functions.php) option.
    Go to the Theme Editor and load functions.php
  2. Add the following code to the bottom of the functions.php file
    add_filter('show_admin_bar', '__return_false');

    Once entered, click the “Update file” button. You admin bar will no longer show.

    Add the following code to the bottom of the functions.php file
Jonathan Griffin. Editor @ The Webmaster

About the author

Editor at The Webmaster.

Jonathan Griffin has been the Lead writer at The Webmaster for the last 5 years. Having provided technical SEO, WordPresss development, and hosting services for clients, his passion remains to help small businesses and bloggers develop their online presence.

In his spare time, he loves to push his technical knowledge further, and regularly undertakes professional courses on subjects ranging from python development, digital marketing, and Google Analytics.

Find out more about Jonathan Griffin on our About Page.