2

I am tired from this problem (I don't know if it's specific to firefox or not).

As some time passes after I log in to my site (or maybe after I close the browser too), I have to log in to my site again. How to stop WP from asking me so frequent logins? Like Facebook does - you log in and that's all until you log out.

I've tried add_filter('auth_cookie_expiration' .... but it didn't help.

p.s. I am using iThemes Security (if it matters).

  • 4
    Does it still happen after you check the Remember Me option (while you log in)? – Fayaz Feb 7 '17 at 14:49
  • @Fayaz I never check that (l dont need to save for 14 days, instead , 48 is enough for me). – T.Todua Feb 7 '17 at 20:07
  • Whitelist your wordpress site on your auto-delete cookie addons and it won't log out so fast anymore. – user147790 Jul 30 '18 at 15:07
4
+50

WordPress keeps you logged in for 48 hours by default.

If you click the "Remember Me" checkbox, it will remember you for 14 days.

If you would like to remain logged in for longer than this period of time, you must use the "Auth Cookie Expiration" hook that WordPress provides. Now, you've mentioned that you've used this without any effect. My geuss is that there is something incorrect in the application of this hook.

Here is an example use of the hook that has been tested and verified by multiple users:

function wpse108399_change_cookie_logout( $expiration, $user_id, $remember ) {
    if( $remember && user_can( $user_id, 'manage_options' ) ){
        $expiration = 60;// yes, I know this is 1 minute
    }
    return $expiration;
}
add_filter( 'auth_cookie_expiration','wpse108399_change_cookie_logout', 10, 3 );

It comes from this WPSE post: Extending auth_cookie_expiration based on user role

Here is an article that goes into depth about extending the auth_cookie_expiration, specifically about how to extend it to a year's time: https://premium.wpmudev.org/blog/how-to-extend-the-auto-logout-period-in-wordpress/

One final idea would be to also hook to the auth_cookie_expired hook, which activates once your authorization cookie officially expires. You could add code to create a new cookie everytime the old cookie expires.

Beyond this, there is no documented way to accomplish what you're asking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.