Using WordPress ‘password_hint’ PHP filter

The password_hint WordPress PHP filter allows you to modify the text describing the site’s password complexity policy.

Usage

add_filter('password_hint', 'my_custom_password_hint');
function my_custom_password_hint($hint) {
    // your custom code here
    return $hint;
}

Parameters

  • $hint (string): The original password hint text.

More information

See WordPress Developer Resources: password_hint

Examples

Simple custom password hint

Add a custom password hint message.

add_filter('password_hint', 'my_custom_password_hint');
function my_custom_password_hint($hint) {
    $hint = 'Please use at least 8 characters, including at least one number and one uppercase letter.';
    return $hint;
}

Add a minimum password length

Specify a minimum password length in the hint.

add_filter('password_hint', 'min_length_password_hint');
function min_length_password_hint($hint) {
    $min_length = 10;
    $hint = "Your password must be at least {$min_length} characters long.";
    return $hint;
}

Specify allowed special characters

List the allowed special characters in the hint.

add_filter('password_hint', 'allowed_special_chars_hint');
function allowed_special_chars_hint($hint) {
    $hint = 'Your password must include at least one special character: !, @, #, $, %, ^, &, *';
    return $hint;
}

Combining multiple password requirements

Combine multiple password requirements in the hint.

add_filter('password_hint', 'combined_password_requirements_hint');
function combined_password_requirements_hint($hint) {
    $hint = 'Your password must be at least 10 characters long, contain at least one number, one uppercase letter, and one of the following special characters: !, @, #, $, %, ^, &, *';
    return $hint;
}

Add a custom hint based on user role

Change the hint based on the user’s role.

add_filter('password_hint', 'custom_hint_based_on_user_role');
function custom_hint_based_on_user_role($hint) {
    if (current_user_can('editor')) {
        $hint = 'As an editor, your password must be at least 12 characters long and contain at least one number, one uppercase letter, and one special character.';
    } else {
        $hint = 'Please use at least 8 characters, including at least one number and one uppercase letter.';
    }
    return $hint;
}