Email PHP Intermediate

Rewrite the Password Reset Email

Replace the plain WordPress password reset email with your own friendly wording and your site's name.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 15 lines
add_filter( 'retrieve_password_message', function ( string $message, string $key, string $user_login, WP_User $user ): string {
	$url = network_site_url( 'wp-login.php?action=rp&key=' . $key . '&login=' . rawurlencode( $user_login ), 'login' );

	return sprintf(
		"Hi %s,\n\nSomeone asked to reset the password for your %s account.\n\nTo choose a new password, open this link:\n%s\n\nThe link works once and expires in 24 hours. If you didn't ask for this, you can ignore this email and your password will stay the same.\n\nThanks,\nThe %s team",
		$user->first_name ?: $user->display_name,
		wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ),
		$url,
		wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES )
	);
}, 10, 4 );

add_filter( 'retrieve_password_title', function (): string {
	return 'Reset your ' . wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) . ' password';
} );

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.

The default reset email shows the username, the site address and a bare link, and can look like phishing. A clear, friendly message gets fewer support requests.

How it works

retrieve_password_message gives you the reset key and the user, so you can build the same reset link WordPress uses and write your own message around it. retrieve_password_title changes the subject.

Site names are decoded with wp_specialchars_decode() so an ampersand shows as “&” in the plain-text email.

Things to watch

  • Keep the link exactly as built here, including 'login' as the URL scheme. Changing it breaks the reset.
  • The “24 hours” matches WordPress’s default. If you use “Shorten Password Reset Link Expiry”, change the text to match.
  • WooCommerce sends its own reset email for the My Account page.

How to test it

Use “Lost your password?” on a test account. The email should use your wording, and the link should open the “Enter a new password” form.

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