Home/Blog/How to Fix WordPress Keeps Logging You Out

How to Fix WordPress Keeps Logging You Out

WordPress keeps logging out fix guide

You log in to WordPress, start working, and minutes later you’re staring at the login screen again โ€” or you keep getting bounced out entirely. It’s maddening. This WordPress keeps logging out fix guide explains why your session keeps dying (expired cookies, URL mismatches, aggressive caching) and six fixes to stay logged in reliably.

What Causes WordPress Keeps Logging Out

WordPress tracks your login with an authentication cookie. If that cookie expires early, gets blocked, or no longer matches your site’s address, WordPress can’t recognize you and drops you back to the login screen. The usual causes:

  • URL mismatch (www vs non-www, http vs https): the auth cookie is scoped to the address in Settings โ†’ General. Browsing a different variant (www vs non-www) means the cookie isn’t sent, so you’re “logged out” instantly.
  • Expired or shortened auth cookie: WordPress logs you out after 48 hours by default (14 days with “Remember Me”). Custom code or a plugin can shorten this dramatically.
  • Cached admin/login pages: server or plugin caching of wp-login.php or /wp-admin/ serves stale pages with old nonces and broken session state โ€” one of the most common causes.
  • Corrupt or stale browser cookies: old cookies from a migration or URL change conflict with new ones.
  • Security/login plugins: session-control, inactivity-logout, or security plugins (and misconfigured object caches like Redis/Memcached with stale session data) can kill sessions aggressively.
  • Wrong server time: WordPress validates auth cookies against timestamps โ€” if the server clock is significantly off, cookies behave as if already expired. Also check Settings โ†’ General โ†’ Timezone. More session guides live on the KamiWeb blog.

How to Fix WordPress Keeps Logging Out

Start simple and reversible: clear this site’s cookies, try another browser, and tick Remember Me when logging in (14 days instead of 48 hours). If logouts continue, work through these fixes with our free web tools handy.

Refreshing browser cookies concept

  1. Clear cookies and match the URLs. Delete cookies and cached data for your domain, then confirm the WordPress Address and Site Address in Settings โ†’ General exactly match the URL you browse (https vs http, www vs non-www). If you’re locked out, force the correct addresses in wp-config.php: define('WP_HOME','https://yoursite.com'); and define('WP_SITEURL','https://yoursite.com');.
  2. Exclude admin and login from all caching. Purge your caching plugin and server cache, then configure exclusions for /wp-admin/ and wp-login.php. On Nginx FastCGI cache, bypass caching when the wordpressloggedin cookie is present. On Cloudflare, add a page rule bypassing cache for yourdomain.com/wp-admin/* and yourdomain.com/wp-login.php. Flush object caches (Redis/Memcached) too โ€” stale session data there breaks validation.
  3. Check plugins and security rules. Deactivate recently added or updated plugins โ€” especially security, login/session, and caching plugins โ€” and test. If you can’t stay logged in long enough, rename plugin folders via FTP. Re-enable one by one to find the culprit, then adjust its session settings instead of removing protection entirely.
  4. Fix the cookie domain. Add define('COOKIE_DOMAIN', false); to wp-config.php above the “stop editing” line to clear up domain-scoped cookie problems. If you previously hardcoded a COOKIE_DOMAIN that no longer matches your domain, update or remove it.
  5. Verify server time and PHP session settings. Ask your host to confirm the server clock is accurate (NTP-synced). Also have them review session.gc_maxlifetime, PHP session configuration, and object-cache settings โ€” misconfigurations here silently kill sessions.
  6. Extend the auth cookie duration. If everything works but sessions just end too soon, add this to a small custom plugin (better than functions.php, so it survives theme changes): add_filter('auth_cookie_expiration', function($e, $u, $r) { return $r? 30 * DAY_IN_SECONDS: 2 * DAY_IN_SECONDS;}, 10, 3); โ€” 30 days with Remember Me, 2 days without. Don’t overdo this on shared computers. Browse KamiWeb’s plugin resources for session-management tools.

Conclusion

The WordPress keeps logging out fix is usually configuration, not a bug: clear cookies, match your URLs exactly, keep caching away from the admin and login pages, and check session-hungry plugins. Start with the reversible fixes before touching code โ€” most logout loops end at step one or two. More fixes at KamiWeb.