0

After password is reset in Wordpress, the message comes as "Your password has been reset. Login" How do I customise this message?

        do_action( 'validate_password_reset', $errors, $user );

        if ( ( ! $errors->has_errors() ) && isset( $_POST['pass1'] ) && ! empty( $_POST['pass1'] ) ) {
            reset_password( $user, $_POST['pass1'] );
            setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
            login_header( __( 'Password Reset' ), '<p class="message reset-pass">' . __( 'Your password has been reset.' ) . ' <a href="' . esc_url( wp_login_url() ) . '">' . __( 'Log in' ) . '</a></p>' );
            login_footer();
            exit;
        }

This is the code I am looking at in wp-login.php. I just want to change the message alone. Any help is appreciated.

1 Answer 1

1

Looking at the login_header() function, it appears that you can use the login_message filter.

add_filter( 'login_message', 'wpse386695_change_message' );
function wpse386695_change_message( $message ) {
    $message = str_replace(
        'Your password has been reset',
        __( 'The text you want to appear', 'plugin-text-domain' ),
        $message
    );
    return $message;
}

Update

To replace the entire login_message string with your own URL (as requested in the comments), you can do this instead:

add_filter( 'login_message', 'wpse386695_replace_message' );
function wpse386695_replace_message( $message ) {
    $message = '<p class="message reset-pass">'
               . __( 'Your password has been reset.' )
               . ' <a href="' . esc_url( 'https://example.com/my-login-url' )
               . '">' . __( 'Log in' ) . '</a></p>'

    return $message;
}

...replacing https://example.com/my-login-url with the URL you need, of course.

5
  • Thank you, worked like a charm! Any idea how to remove the Log in hyperlink that comes after the text? Apr 16, 2021 at 4:02
  • Are you trying to remove the entire "Your password has been changed. Log in" text?
    – Pat J
    Apr 16, 2021 at 4:22
  • I need the message, but the login link to be changed to different URL. If that's not possible then remove the login link. Apr 16, 2021 at 6:19
  • I've updated the answer to address what you're asking for.
    – Pat J
    Apr 16, 2021 at 13:30
  • Thanks, I am able to change the text now. But the modified text shows up before resetting the password itself. When user clicks on password reset URL, the text is shown there on top. It needs to appear only after password is reset. Apr 18, 2021 at 2:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.