FOLLOW ME Twitter Facebook Вконтакте LinkedIn RSS Feed

How to extend the WordPress cookie timeout

Category: Tips and Tricks
Dec 30, 2013
Konstantin Bulenkov

First of all: I really like WordPress. I’ve been using it since 2004 or so. At the moment I’m registered on a several WordPress-based web-sites where I write comments and interact with other people from time to time. The thing I really don’t understand in the WordPress architecture is why WordPress has hard-coded cookie timeout for only 14 days? It makes me angry all the time I see that a WP-based web-site forgot who I am.

Hopefully, if you’re a web-site administrator, this is an easy-to-fix problem. All you need is to slightly change your current theme’s function.php file. What you should do:
1. Go to the Admin Panel and then Appearance -> Editor
2. Click on Theme Functions (functions.php)
3. Paste this code to the end of the file, but before ?> ending tag.

/*******************************
 * COOKIE TIMEOUT EXTENDER     *
 *******************************/
function custom_auth_cookie_expiration($date) {
  return 365 * 24 * 60 * 60; // one year in seconds
}

add_filter('auth_cookie_expiration', 'custom_auth_cookie_expiration');

365 here is a number of days. You can change it as you wish.

Leave a comment