
You can increase the WordPress login session duration by adding a function to your theme’s functions.php file. To do this, you’ll use the auth_cookie_expiration filter to modify the default cookie expiration time. Here’s a function you can add to your functions.php file to extend the login session duration for logged-in users:
function extend_login_session_duration($expiration, $user_id, $remember) {
if ($remember) {
// Change the session duration to your desired time in seconds (e.g., 2 weeks = 14 days)
$extended_expiration = 14 * DAY_IN_SECONDS;
return $extended_expiration;
}
return $expiration;
}
add_filter('auth_cookie_expiration', 'extend_login_session_duration', 10, 3);
In this code:
- The
extend_login_session_durationfunction is defined. It takes three parameters:$expiration(the default session expiration time),$user_id(the user’s ID), and$remember(a boolean indicating whether the “Remember Me” option was selected during login). - Inside the function, we check if the “Remember Me” option was selected (
$rememberistrue). If it was, we set a custom expiration time (in this example, 14 days) by multiplying theDAY_IN_SECONDSconstant by the number of days you want the session to last. - Finally, we return the updated expiration time if the “Remember Me” option is checked, or the default expiration time if it’s not.
This code will extend the login session duration for users who check the “Remember Me” option when logging in, allowing them to stay logged in longer. Adjust the value 14 to your desired number of days to control the session duration.
Security Considerations
Extending the login session duration can have security implications, so it’s essential to consider potential risks and take precautions when implementing this change. Here are some security concerns and ways to mitigate them:
- Increased Exposure to Session Hijacking: The longer a user remains logged in, the more time a potential attacker has to steal their session cookies. To mitigate this risk, consider implementing additional security measures such as two-factor authentication (2FA) or regularly prompting users to re-authenticate.
- Lost or Stolen Devices: If a user’s device with an active, long-duration session is lost or stolen, it could provide unauthorized access to their account for an extended period. Users should be encouraged to log out when they’re done using a shared or public computer.
- Session Fixation Attacks: Extending session durations may make session fixation attacks more potent. To prevent this, WordPress generates a new session ID upon login. Ensure your WordPress installation is up to date to benefit from security improvements.
- Server Resource Usage: Longer sessions can increase server resource usage since each active session consumes memory and processing power. Make sure your server can handle the increased load, especially on high-traffic websites.
- User Awareness: Users may forget that they’re logged in if sessions last a very long time, which could lead to unintended access. You should educate users about the session duration and how to log out if necessary.
- Data Privacy Regulations: If you’re subject to data privacy regulations like GDPR, be sure to inform users about the extended session duration in your privacy policy and obtain their explicit consent if required.
- Monitoring and Logging: It’s essential to have robust monitoring and logging in place to detect and respond to suspicious activities. Regularly review your logs for any unusual login or access patterns.
Extending session duration can improve user convenience, it should be done carefully with security in mind. Consider implementing additional security measures and educating users about the potential risks associated with longer sessions. Always keep your WordPress installation and plugins up to date to benefit from security patches and improvements.
More helpful posts

12 Essential Steps to Fortify Your WordPress Security in 2025
With cyber threats looming larger than ever, securing your online presence is paramount. With WordPress powering over 40% of all websites, its popularity makes it a prime target for hackers...
Customizing Your WordPress Author Slug: Tips and Tricks
Have you ever come across a messy URL that makes you question its credibility? Author slugs play a significant role in web addresses and can influence both usability and SEO....
Building Trust: Your Wollongong Website’s Secret Weapon
Alright, Wollongong businesses, let’s chat about building that rock-solid trust online! You know, that feeling where a potential customer lands on your website and thinks, “Yep, these guys get it....