How to Stop WordPress Auto-Logout in Local Development?

Share to

Ever wondered how to stop WordPress auto-logout in local development? Same here.

One of the most frustrating things when working on WordPress locally is getting logged out all the time. You’re in the middle of testing a feature, writing some content, or tweaking a plugin, and suddenly you’re back at the login screen. This is even more annoying when working on a local server like XAMPP or Laragon, where development is supposed to be fast and seamless.

By default, WordPress login cookies expire in about two days if you don’t check Remember Me, or 14 days if you do. This makes sense in production environments where security is important, but in local development, this behavior quickly gets in the way. Fortunately, there’s a very simple fix.

Table of Contents

WordPress has a filter called auth_cookie_expiration which lets you change how long login cookies stay valid. By hooking into it, we can set a much longer duration to days, months, or even years.

This way, when you’re working locally, you won’t be forced to log in over and over again.

The Solution: A Small MU-Plugin

The easiest and most reliable way to make this permanent is to use an MU-plugin (must-use plugin). Unlike regular plugins, MU-plugins are always loaded and don’t need to be activated from the dashboard. That makes them perfect for small tweaks like this.

Create a folder called mu-plugins inside your wp-content directory (if it doesn’t already exist). Then create a PHP file, for example extend-login-cookie.php, with the following code:

<?php
/**
* Mu-plugin: Extend login cookie duration (for local development)
*/

add_filter('auth_cookie_expiration', function($length, $user_id, $remember) {
$days = 365 * 10; // 10 years
return $days * DAY_IN_SECONDS;
}, 10, 3);

That’s it. Now, whenever you log in, your session will last up to 10 years unless you manually log out or clear cookies in your browser. To apply the new cookie duration, simply log out and log back in once, this ensures the updated setting takes effect.

Why MU-Plugin Instead of Functions.php?

At first glance, you might think the simplest place to add this snippet is inside your theme’s functions.php file. Technically, that would work, WordPress will load the code, and your login cookies will last much longer. However, there are a couple of problems with that approach.

The biggest issue is theme dependency. If you ever change your theme, deactivate it, or switch to a new starter theme for development, you’ll lose the modification. You’d have to remember to copy and paste the code again, which is both error-prone and time-consuming.

Another issue is maintainability. Theme files are meant to handle presentation, styling, and sometimes minor functionality related to the theme itself. Overloading functions.php with environment-specific tweaks like login duration makes your code harder to organize and track.

By contrast, an MU-plugin (Must-Use Plugin) is always loaded by WordPress, regardless of which theme is active. It lives in its own folder (wp-content/mu-plugins/), which makes it easy to manage, share, and even version-control separately. You can think of it as a “global tweak” that stays in effect no matter how your site’s look and feel changes.

For these reasons, MU-plugins are the cleaner and more professional choice when applying developer-focused adjustments such as extending cookie expiration.

A Word of Caution

While this solution is incredibly handy for local development, it comes with an important caveat: do not use it in production environments. The default WordPress session length exists for a reason, it helps reduce security risks by limiting the time a stolen cookie can be abused.

Imagine setting your admin cookie to last ten years on a live website. If your laptop gets stolen, or your browser is compromised, an attacker could gain continuous access to your WordPress dashboard without ever needing to log in again. That’s essentially leaving the front door wide open.

For local workstations, the risk is minimal since your site isn’t exposed to the public. Convenience clearly outweighs security in that scenario. But once your project goes online, you should always revert to the default behavior or choose a much shorter duration if you absolutely must extend it.

In short: long-lived cookies are for development only. When your site goes public, make security your top priority.

Conclusion

By dropping a simple MU-plugin into your WordPress installation, you can eliminate one of the biggest annoyances of local development: the constant auto-logout. Now you can stay logged in for as long as you need while working with WordPress in Laragon (or any local server).

Happy coding and may you never have to type your password again while building locally!

If you found this helpful, feel free to explore more tips and insights on my website Kotak Digital.

Found this post helpful? Spread the word by sharing “How to Stop WordPress Auto-Logout in Local Development?” with your network. At Kotak Digital, we are passionate about delivering insights, tips, and resources to help you stay ahead in the digital world.

Share to

Related Post

n8n vs Zapier Which Automation Platform Should You Use in 2025

n8n vs Zapier: Which Automation Platform Should You Use in 2025?

As businesses and individuals seek to streamline their workflows, the question of which automation platform to choose becomes crucial. In the debate of n8n vs Zapier, both tools have gained significant traction in the automation landscape, each catering to different needs. If you’ve been following our journey at Kotak Digital, you know we’re passionate about…
How to Remove twitterlabel & twitterdata Meta Tags in WordPress

How to Remove twitter:label & twitter:data Meta Tags in WordPress

When managing a WordPress website, especially if you care about SEO and social sharing optimization, you’ve likely encountered additional meta tags that are automatically added to your site’s <head>. Some of these include twitter:label1, twitter:data1, twitter:label2, and twitter:data2. While they may serve a purpose for certain scenarios, many webmasters and developers find them unnecessary or…
10 Essential WordPress Plugins for Developers in 2025 - Kotak Digital Kotaqx

10 Essential WordPress Plugins for Developers in 2025

In 2025, the landscape of WordPress development continues to evolve, making it essential for developers to equip themselves with the right tools. This Essential WordPress Plugins for Developers in 2025 are not just about enhancing functionality; they can dramatically streamline your workflow, saving precious time and effort. Here at Kotak Digital, we believe in empowering…
install n8n, n8n docker, self-hosted n8n, docker tutorial, n8n setup

How to Install n8n Using Docker (Step-by-Step)

If you're looking to install n8n, you're in the right place! n8n is a powerful open-source automation tool that allows you to connect different applications and automate workflows, making it an excellent choice for developers who want to run an automation server locally or on a private VPS. At Kotak Digital, we believe in empowering…

Leave the first comment