admin管理员组

文章数量:1295065

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.

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.

Share Improve this question asked Apr 16, 2021 at 2:30 GeneralNinjaGeneralNinja 11 silver badge1 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 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/my-login-url' )
               . '">' . __( 'Log in' ) . '</a></p>'

    return $message;
}

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

本文标签: customizationChange Successful password reset message