How to logout a user when he closes the tab/window ?

If no, it is possible to clear the session after specific time? How to do that?

  • If I am reading the question right, this is either a Javascript question and off-topic here, or a (near) duplicate of this question: wordpress.stackexchange.com/questions/108399/… – s_ha_dum Nov 10 '13 at 14:45
  • It doesn't seem to work properly on custom login. When Session expires, I'm unable to login . – rgb Nov 11 '13 at 15:28

I worked long on this one. It is because of the WordPress remember me. Use this code in your theme's functions.php and it should fix your issue:

function myplugin_cookie_expiration( $expiration, $user_id, $remember ) {
    return $remember ? $expiration : 180;
add_filter( 'auth_cookie_expiration', 'myplugin_cookie_expiration', 99, 3 );

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.