Change Password Cookie Expiration WordPress: 2 Simple Ways

If you need to change password cookie expiration WordPress, you have two options: add a PHP filter to your functions.php file, or set it directly from the PPWP Pro plugin settings – no code required for the second method.

By default, WordPress stores password cookies for 10 days. That means once a visitor enters the correct password on a protected page, they will not be asked to re-enter it for 10 days. Depending on your use case, that default may be too long or too short.

🍪 How Does WordPress Store Password Cookies?

When a visitor enters the correct password on a password protected page, WordPress creates a cookie called wp-postpass and stores it in their browser. That cookie tells WordPress the visitor has already authenticated, so they are not asked to enter the password again on their next visit.

That means if you protect multiple pages with the same password, the visitor only needs to enter it once. WordPress will recognize the cookie and grant access to all pages protected with that same password.

Here’s why the default matters: WordPress sets that cookie to expire after 10 days. After that, the visitor has to re-enter the password. If your content is meant for a one-day event, or if you want to limit access to a specific time window, the default does not work for your use case.

⚙️ How to Change Password Cookie Expiration WordPress Using PHP

The PHP method works on any WordPress site, regardless of which plugins you have installed. It uses the post_password_expires filter to override the default 10-day expiration time.

Here’s how it works:

  • In your WordPress dashboard, go to Appearance, then Theme File Editor.
  • In the left panel, click on the functions.php file of your active theme.
  • Scroll to the bottom of the file and paste this code:

function mind_set_cookie_expire( $time ) { return time() + 86400; } add_filter( 'post_password_expires', 'mind_set_cookie_expire' );

On line 2, replace 86400 with the number of seconds you want the cookie to last. 86400 equals one day. To calculate any other value, multiply the number of days you want by 86400.

For example:

  • 1 day: 86400
  • 3 days: 259200
  • 7 days: 604800
  • 30 days: 2592000

Click Update File to save.

In other words, once the file is saved, WordPress will apply the new expiration time to every new cookie it creates on password protected pages across your site.

Important: if you already have an active cookie in your browser, delete it first and reload the page. Then re-enter the password to see the new expiration time take effect. You can use a cookie inspector tool to verify the new expiration date on the wp-postpass cookie.

🔒 How to Change Password Cookie Expiration WordPress Without Code Using PPWP Pro

If you prefer to avoid editing theme files, the Password Protect WordPress Pro plugin lets you change password cookie expiration WordPress directly from the plugin settings – no code required.

Here’s how it works:

  • Install and activate the PPWP Pro plugin.
  • Open the page or post you want to protect. Look for the Password Protect WordPress column, click Password Protect, then Password Protect this page.
  • Copy the generated password, then go to the PPWP Pro settings page.
  • Find the option labeled Cookie Expiration Time. The default value is 3 days.
  • Enter the number of days you want the cookie to last.
  • Click Save Changes.

From that point on, visitors who enter the correct password will not be asked to re-enter it until the number of days you set has passed.

Keep in mind: this setting only applies to content that already has a password assigned. If a page or post has no password, the cookie setting has no effect.

As with the PHP method, delete any active cookie first to see the new expiration time take effect.

❓ Frequently Asked Questions

How long does a WordPress password cookie last by default?

By default, WordPress stores password cookies for 10 days. After that, visitors must re-enter the password to access protected content.

Can I change password cookie expiration WordPress without a plugin?

Yes. You can add the post_password_expires filter to your functions.php file to set a custom expiration time in seconds.

How do I calculate the number of seconds for a custom cookie expiration?

Multiply the number of days you want by 86400. For example, 3 days equals 259200 seconds.

Does the PPWP Pro cookie setting apply to all protected pages?

The setting applies to all content that already has a password assigned through PPWP Pro. If a page or post has no password, the cookie setting has no effect.

How can I verify that the new cookie expiration time is working?

Delete any active cookie in your browser, re-enter the password on the protected page, and use a cookie inspector tool to check the expiration date on the wp-postpass cookie.

Video Transcript

How do you change the password cookie expiration time on a WordPress protected page?

By default, WordPress stores password cookies for 10 days. But depending on your use case, that may be too long or too short. Here’s how to set your own expiration time.

You have two options: add a filter to your functions.php file, or set it directly with the Password Protect WordPress Pro plugin. The PHP method works on any WordPress site. The PPWP method requires no code.

METHOD 1: functions.php file.

Step 1. In your WordPress dashboard, go to Appearance, then Theme File Editor.

Step 2. In the left panel, click on the functions.php file.

Step 3. Paste this code at the bottom of the file: function mind_set_cookie_expire( $time ) { return time() + 86400; } add_filter( ‘post_password_expires’, ‘mind_set_cookie_expire’ );

Step 4. On line 2, replace 86400 with the number of seconds you want. 86400 equals one day. To calculate any other value, simply multiply the number of days you want by 86400.

Then click Update File.

If you already have an active cookie, delete it first and reload the page. Then re-enter the password to see the new expiration time take effect. To verify the change, you can use a cookie inspector tool to check the expiration date on the wp-postpass cookie.

That’s it for the PHP method. The cookie will now expire after the time you set.

METHOD 2: If you prefer to avoid code, here’s how to do the same thing with the Password Protect WordPress Pro plugin.

Step 1. Install and activate the plugin. Then you need to password protect your page or post. To do that, open the page or post you want to protect, look for the Password Protect WordPress column, click Password Protect, then Password Protect this page.

That’s it, your page is now password protected. Copy the generated password and go to the PPWP settings page.

Step 2. Find the option labeled Cookie Expiration Time. The default value is 3 days.

Step 3. Enter the number of days you want the cookie to last.

Step 4. Click Save Changes.

As before, delete any active cookie first to see the new expiration time take effect.

Keep in mind this setting only applies to content that already has a password assigned. If not, the cookie setting has no effect.

From that point on, visitors who enter the correct password will not be asked to re-enter it until the number of days you set has passed.

Subscribe for more WordPress security tutorials.