WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to clear the session cookie when a user logs out or when their session expires. I understand that wp_clear_auth_cookie(); clears the cookie but I am struggling to understand how to implement it. I am using the following code to log a user out automatically if they are inactive for 10 minutes. (I think I found that in here too)

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

Could someone kindly direct me to the right direction to achieve this result?

share|improve this question
Maybe I got you wrong, but isn't that exactly what WP does when the current user is about to log out? Clearing the cookie, that is. – tfrommen Mar 14 '13 at 15:23
It only works if the user closes the browser and reopens it. If not it uses the same authentication cookie. That's what I'm trying to avoid. – user1809542 Mar 23 '13 at 19:54

Try setting $experation to a negative integer:

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

From the w3schools PHP page on cookies:

// set the expiration date to one hour ago
setcookie("user", "", time()-3600);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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