Title: auth_cookie_expiration
Published: April 25, 2014
Last modified: May 20, 2026

---

# apply_filters( ‘auth_cookie_expiration’, int $length, int $user_id, bool $remember )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/?output_format=md#wp--skip-link--target)

Filters the duration of the authentication cookie expiration period.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/?output_format=md#parameters)󠁿

 `$length`int

Duration of the expiration period in seconds.

`$user_id`int

User ID.

`$remember`bool

Whether to remember the user login. Default false.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/?output_format=md#source)󠁿

    ```php
    $expiration = time() + apply_filters( 'auth_cookie_expiration', 14 * DAY_IN_SECONDS, $user_id, $remember );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/pluggable.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/pluggable.php#L1082)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/pluggable.php#L1082-L1082)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/?output_format=md#related)󠁿

| Used by | Description | 
| [wp_set_auth_cookie()](https://developer.wordpress.org/reference/functions/wp_set_auth_cookie/)`wp-includes/pluggable.php` |

Sets the authentication cookies for a given user ID.

  | 
| [wp_update_user()](https://developer.wordpress.org/reference/functions/wp_update_user/)`wp-includes/user.php` |

Updates a user in the database.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 5 content](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/?output_format=md#comment-content-1773)
 2.    [Ethan O’Sullivan](https://profiles.wordpress.org/ethanosullivan/)  [  10 years ago  ](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/#comment-1773)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fauth_cookie_expiration%2F%23comment-1773)
     Vote results for this note: 6[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fauth_cookie_expiration%2F%23comment-1773)
 4.  An example of how to extend time in your WordPress session by a year, simply enter
     this code into your `functions.php` or plugin. Other durations have been added
     to show different times hat can be set.
 5.      ```php
         add_filter ( 'auth_cookie_expiration', 'wpdev_login_session' );
     
         function wpdev_login_session( $expire ) { // Set login session limit in seconds
             return YEAR_IN_SECONDS;
             // return MONTH_IN_SECONDS;
             // return DAY_IN_SECONDS;
             // return HOUR_IN_SECONDS;
         }
         ```
     
 6.   * It’s best to consider the $remember parameter and assign a shorter expiry when
        $remember is false (or leave it default). WP uses the difference between cookie
        expiry with and without “Remember me” as a heuristic flag in `wp_update_user()`.
        After a password change, it guesses the user wants “Remember me” if the current
        cookie time left is longer than what this filter returns with $remember = false.
        Comment based on WP 5.0.2.
      * [kitchin](https://profiles.wordpress.org/kitchin/) [7 years ago](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/#comment-3029)
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fauth_cookie_expiration%2F%3Freplytocom%3D1773%23feedback-editor-1773)
 8.   [Skip to note 6 content](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/?output_format=md#comment-content-2271)
 9.    [polev](https://profiles.wordpress.org/polev/)  [  9 years ago  ](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/#comment-2271)
 10. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fauth_cookie_expiration%2F%23comment-2271)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fauth_cookie_expiration%2F%23comment-2271)
 11. Extension of the example, only extending expiration if $remember and low privelege.
 12.     ```php
         add_filter('auth_cookie_expiration', 'auth_cookie_expiration_filter_5587', 10, 3);
         function auth_cookie_expiration_filter_5587($expiration, $user_id, $remember) {
             if ($remember && !user_can($user_id, 'edit_others_posts')) {
                 return YEAR_IN_SECONDS;
                 // return MONTH_IN_SECONDS;
                 // return DAY_IN_SECONDS;
                 // return HOUR_IN_SECONDS;
             }
             // default
             return $expiration;
         }
         ```
     
 13.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fauth_cookie_expiration%2F%3Freplytocom%3D2271%23feedback-editor-2271)
 14.  [Skip to note 7 content](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/?output_format=md#comment-content-3299)
 15.   [kmvan](https://profiles.wordpress.org/kmvan/)  [  7 years ago  ](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/#comment-3299)
 16. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fauth_cookie_expiration%2F%23comment-3299)
     Vote results for this note: -2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fauth_cookie_expiration%2F%23comment-3299)
 17.     ```php
         // forever
         add_filter('auth_cookie_expiration', function (int $length): int {
             return PHP_INT_MAX;
         });
         ```
     
 18.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fauth_cookie_expiration%2F%3Freplytocom%3D3299%23feedback-editor-3299)
 19.  [Skip to note 8 content](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/?output_format=md#comment-content-2600)
 20.   [Zübeyir Muştak](https://profiles.wordpress.org/abulogics/)  [  8 years ago  ](https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/#comment-2600)
 21. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fauth_cookie_expiration%2F%23comment-2600)
     Vote results for this note: -3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fauth_cookie_expiration%2F%23comment-2600)
 22.     ```php
         function wp_homework_change_cookie_logout( $expiration){
         	$user = wp_get_current_user();
         	$allowed_roles = array('administrator', 'scholar');
         		 if( array_intersect($allowed_roles, $user->roles ) ) { 
         		   $expiration = 31557600;
         		 } 
             return $expiration;
         }
     
         add_filter( 'auth_cookie_expiration','wpse108399_change_cookie_logout', 10, 3 );
         ```
     
 23.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fauth_cookie_expiration%2F%3Freplytocom%3D2600%23feedback-editor-2600)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fauth_cookie_expiration%2F)
before being able to contribute a note or feedback.