How can i increase or decrease the lifetime of the login cookie in WordPress?

in #utopian-io9 years ago (edited)

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.

login-formular-wordpress.png

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.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.083
BTC 60737.85
ETH 1558.46
USDT 1.00
SBD 0.50