How can i increase or decrease the lifetime of the login cookie in WordPress?
If you log in to your WordPress website you have the possibility to activate the option Remember Me. If you activate this checkbox, the lifetime of the cookie or login session is 14 days. If you omit the checkmark, the cookie has a lifespan of only two days.
If this time span is not sufficient for you, you have the possibility to adjust it. With the following code in the functions.php of the active theme, the lifetime of the login cookie is extended to one month:
add_filter ( 'auth_cookie_expiration', 'wpdev_login_session' );
function wpdev_login_session( $expire ) {
return MONTH_IN_SECONDS;
}
You can also find this code snippet as a Gist on GitHub..
MONTH_IN_SECONDS is a WordPress constant and is defined in the file /wp-includes/default-constants.php in line 125. In addition to this, there are also other time constants:
define( 'MINUTE_IN_SECONDS', 60 );
define( 'HOUR_IN_SECONDS', 60 * MINUTE_IN_SECONDS );
define( 'DAY_IN_SECONDS', 24 * HOUR_IN_SECONDS );
define( 'WEEK_IN_SECONDS', 7 * DAY_IN_SECONDS );
define( 'MONTH_IN_SECONDS', 30 * DAY_IN_SECONDS );
define( 'YEAR_IN_SECONDS', 365 * DAY_IN_SECONDS );
If you prefer a plugin instead, you will find a good solution in WP Login Timeout Settings, which also offers some extras, such as setting different login times for users with different rights.
- The time constants in the file default-constants.php
- Code Reference: auth_cookie_expiration
- The plugin solution: WP Login Timeout Settings
Posted on Utopian.io - Rewarding Open Source Contributors

Thank you for your contribution. It has been approved.
You can contact us on Discord
For posting rules, check Rules
[utopian-moderator]
Thank you @mcfarhat!
Hey @vladimir-simovic I am @utopian-io. I have just upvoted you at 3% Power!
Achievements
Suggestions
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Vote for my Witness. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x