How to Extend login session times to a Month

How can I extend wordpress login sessions to a month so that it doesn’t automatically ask for login after 48 hours?

I am basically testing some program with wordpress and around 48 hours it fails and I’m pretty sure it has to do with the session id… So please help me extend it to at least a month!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

By default the login cookie lasts for

  • 14 days if you tick ‘remember me’
  • 48 hours if you don’t

So as a short term fix you probably want to tick ‘remember me’, and to extend that to 30 days you can add an auth_cookie_expiration filter e.g.

function auth_cookie_expiration_30_days( $seconds, $user_id, $remember_me ) {
    if ( $remember_me ) {
        return 30 * DAY_IN_SECONDS;
    }
    
    return $seconds;
}
add_filter( 'auth_cookie_expiration', 'auth_cookie_expiration_30_days', 10, 3 );

As you can see you can set per-user-ID durations and you can change the don’t-remember-me time here too if you want, although above I’m leaving that as the default.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x