Keep Users Logged in For Longer in WordPress

How to Keep Users Logged in For Longer in WordPress

in WordPress Admin
Google+ LinkedIn

By default WordPress keep users logged in for maximum of 48 hours before logging them out or if they chose to close the browser before. If you click on “Remember Me” checkbox on the login page of your website, WordPress will keep you logged in for 14 days before logout and require you to re-authenticate again. What WordPress does, is create a login session cookie upon user login and set expiration date accordingly. After that time period, session cookie expires automatically and WordPress requires user to login again.

It’s a security feature but if you manage number of WordPress websites then it becomes really very difficult to keep track of all of your highly complex username & password combinations. Searching for right credentials every two weeks can be a big hassle too. To help you with this issue, we can extend auto logout period in WordPress and keep users logged in for longer period than just 2 weeks.

Paste this following code snippet in your functons.php file to increase the expiration time of the login session cookies, so that users can stay logged in longer.

// keep users logged in for longer in wordpress
function wcs_users_logged_in_longer( $expirein ) {
    // 1 month in seconds
    return 2628000;
}
add_filter( 'auth_cookie_expiration', 'wcs_users_logged_in_longer' );

It’s important to note that the time in above functions is in seconds and we set users to stay logged in for a maximum period of 1 month.

source

Share the love

If you like this snippet, share it with others!

Leave a Reply

Your email address will not be published. Required fields are marked *