Do you want to modify your default Forgot password mail content ? Here we will learn how to customize Reset Password Email content in WordPress. Just copy paste the below code in function.php file :

Customize Reset Password Email content

function codecanal_reset_password_message( $message, $key ) {

    if ( strpos($_POST['user_login'], '@') ) {
        $user_data = get_user_by('email', trim($_POST['user_login']));
    } else {
        $login = trim($_POST['user_login']);
        $user_data = get_user_by('login', $login);
    }

    $user_login = $user_data->user_login;

    $msg = __('The password for the following account has been requested to be reset:'). "\r\n\r\n";
    $msg .= network_site_url() . "\r\n\r\n";
    $msg .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
    $msg .= __('If this message was sent in error, please ignore this email.') . "\r\n\r\n";
    $msg .= __('To reset your password, visit the following address:');
    $msg .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n";

    return $msg;

}

add_filter('retrieve_password_message', codecanal_reset_password_message, null, 2);

Is your reset password key missing in the reset password email?

Is your site is not showing reset password link in reset password email ? Some times some site owners get this type of complain that their subscribes or site users are not getting new password link in mail and that’s why they are not able to login into the site. This situation is very difficult for the member focused websites. It may be cause lose of those users. You can fix the issue by just pasting below code in your function.php file :


/* Start Of Function for changing the Forgot password mail content */
add_filter('retrieve_password_message', 'codecanal_forgot_mail_contnet', 10, 2);

function codecanal_forgot_mail_contnet($message, $key) {

    $user_data = '';
    // If no value is posted, return false
    if (!isset($_POST['user_login'])) {
        return '';
    }
    // Fetch user information from user_login
    if (strpos($_POST['user_login'], '@')) {

        $user_data = get_user_by('email', trim($_POST['user_login']));
    } else {
        $login = trim($_POST['user_login']);
        $user_data = get_user_by('login', $login);
    }
    if (!$user_data) {
        return '';
    }
    $user_login = $user_data->user_login;
    $user_email = $user_data->user_email;

    $site_url = get_site_url();

    $reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login');

    // here $message it the mail content , which you can modify as per your requirment and $key is activation key
    // after modifying you must return $message
    return $message . "- <a href=' " . $reset_url . " '> click Here </a>";
}

/* End Of Function for changing the Forgot password mail content */
There are currently no comments.