0

enter image description here

Please see my screenshot. I want to change the "New Password" label text and "login" text. I used following code to change the hint text.

function change_password_hint ( $text ) {
    if(basename($_SERVER["SCRIPT_NAME"])=='wp-login.php' && $text == 'Hint: The password should be at least twelve characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ & ).'){
        $text = 'Use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ & ).';
    }


    return $text;
}
add_filter( 'gettext', 'change_password_hint' );

How can i change the label and footer text??

1

If we want to have the reset password form to look like this:

reset

then we could use the following hooks:

/**
 * Modify the password hint
 */
add_filter( 'password_hint', function( $hint )
{
  return __( 'Use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ & ).' );
} );

/**
 * Modify 'New password' text
 */
add_action( 'validate_password_reset', function( $errors )
{
    add_filter( 'gettext', 'wpse_gettext', 10, 2 ); 
    return $message;
});


/**
 * Modify 'Log in' text
 */
add_action( 'resetpass_form', function()
{
    add_filter( 'gettext', 'wpse_gettext', 10, 2 ); 
});

The wpse_gettext helper function is defined as:

function wpse_gettext( $translated_text, $text )
{
    // Modify gettext if there's a match
    switch ( $text )
    {
        case 'New password' :           
            remove_filter( current_filter(), __FUNCTION__ );
            $translated_text = __( 'Use this password, or type a new one over it' );
            break;
        case 'Log in' :
            remove_filter( current_filter(), __FUNCTION__ );
            $translated_text = __( 'Already registered before? Click here to log-in' );
            $match = true;          
        default:
    }  
    return $translated_text;
} 

where we remove the filter callback as soon as it has been used once.

We also try to hook into nearby hooks to minimize the number of gettext checks.

Also note the danger of using gettext functions within the gettext filter ;-)

That's why I moved the remove_filter above the __() calls, to avoid infinite loops.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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