Security PHP Beginner

Make Password Reset Links Expire Faster

Make "reset your password" links expire after one hour instead of WordPress's default of one day.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 3 lines
add_filter( 'password_reset_expiration', function (): int {
	return HOUR_IN_SECONDS;
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

A password reset link is as good as a password until it expires. WordPress keeps them valid for 24 hours. If an inbox is compromised or an email is forwarded, a shorter window means less risk.

How it works

The password_reset_expiration filter sets how long reset keys stay valid, in seconds. Returning HOUR_IN_SECONDS means a link older than an hour shows “Your password reset link has expired” and the user requests a new one.

Things to watch

  • Slow email delivery can eat into the hour. If users complain about expired links, try 2 or 4 hours.
  • WooCommerce’s My Account password reset uses the same keys, so it gets the shorter expiry too.

How to test it

Request a password reset, wait just over an hour and open the link. You should see the expired message.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only