Wordpress - Missing URL in password reset email
The problem is the <
and >
which surround the reset URL in wp-login.php
. You can remove them using retrieve_password_message in your theme functions.php
file like below:
add_filter("retrieve_password_message", "mapp_custom_password_reset", 99, 4);
function mapp_custom_password_reset($message, $key, $user_login, $user_data ) {
$message = "Someone has requested a password reset for the following account:
" . sprintf(__('%s'), $user_data->user_email) . "
If this was a mistake, just ignore this email and nothing will happen.
To reset your password, visit the following address:
" . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . "\r\n";
return $message;
}
If you only want to remove the angle brackets WordPress added but let the rest of the generated message unchanged, add the following to the functions.php
of your WordPress theme (eg. wp-content/themes/some_awesome_theme/functions.php
).
/**
* Removes angle brackets (characters < and >) arounds URLs in a given string
*
* @param string $string The string to remove potential angle brackets from
*
* @return string $string where any angle brackets surrounding an URL have been removed.
*/
function remove_angle_brackets_around_url($string)
{
return preg_replace('/<(' . preg_quote(network_site_url(), '/') . '[^>]*)>/', '\1', $string);
}
// Apply the remove_angle_brackets_around_url() function on the "retrieve password" message:
add_filter('retrieve_password_message', 'remove_angle_brackets_around_url', 99, 1);