I understand that the following filter modifies the parameters of the authentication cookies, in fact I have managed to modify its value since it is the first parameter $cookie, but what I need is to modify the parameter $expiration that translates to Expires in the cookie.

So how could I modify the third parameter $expiration given that only $cookie can be returned and the rest seem to be in context?

add_filter( "auth_cookie", "modify_auth_cookie_defaults", 10, 5 );
function modify_auth_cookie_defaults($cookie, $user_id, $expiration, $scheme, $token) { 

return str_replace( $expiration, DAY_IN_SECONDS, $expiration );

add_filter( "auth_cookie", "modify_auth_cookie_defaults", 10, 5 );
function modify_auth_cookie_defaults($cookie, $user_id, $expiration, $scheme, $token) { 
$expiration = YEAR_IN_SECONDS
return $expiration; 

1 Answer 1


You can't modify the parameters of a filter like that, that's not what they're there for. In the source code it'll look something like this:

$cookie = apply_filters( $cookie, $user_id, $expiration, $scheme, $token ); 

It's explicitly looking for the value of $cookie. If you return the value for $expiration, things will break. The extra parameters are there so filtering can be restricted to specific situations, like only for a certain user.

However you can modify the expiration with a different approach. The function that contains the auth_cookie filter is wp_generate_auth_cookie(). This function appears to only be used (in core at least) by the function wp_set_auth_cookie(). If we look at that function, we can see the auth_cookie_expiration filter. This filter is what creates the $expiration value that is passed to the original auth_cookie filter.

TL;DR, use the auth_cookie_expiration filter instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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