Web Development / WordPress

How to Fix the WordPress Admin Bar Showing When Logged Out

Oct 28, 2022
3 min read
Fix the WordPress Admin Bar.

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 its links will work.
  • It’s easy to fix - I will help you solve your problem in just two minutes. I promise.

I know 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. Essentially, 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, it is loaded from the cache rather than built on demand.

This significantly speeds up the render time of your webpage and reduces 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 that 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.

You only see a cached version of the Admin Bar when logged out. 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.

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 geared explicitly towards CloudFlare users, it will also fix the problem caused by any other caching plugin or caching service, including W3 Total Cache.