Using WordPress ‘login_messages’ PHP filter

The login_messages WordPress PHP Filter allows you to modify instructional messages displayed above the login form.

Usage

add_filter('login_messages', 'your_custom_function');
function your_custom_function($messages) {
    // your custom code here
    return $messages;
}

Parameters

  • $messages (string) – Login messages displayed above the form.

More information

See WordPress Developer Resources: login_messages

Examples

Change default login message

Customize the login message to make it more friendly.

add_filter('login_messages', 'customize_login_message');
function customize_login_message($messages) {
    $messages = 'Welcome! Please enter your credentials to log in.';
    return $messages;
}

Add a security warning

Add a warning about potential security threats.

add_filter('login_messages', 'add_security_warning');
function add_security_warning($messages) {
    $messages .= '<br><strong>Notice:</strong> Only authorized users are allowed. Unauthorized access will be prosecuted.';
    return $messages;
}

Display a maintenance message

Inform users about scheduled maintenance.

add_filter('login_messages', 'show_maintenance_message');
function show_maintenance_message($messages) {
    $messages .= '<br><em>Maintenance notice:</em> Our site will be down for maintenance on April 20th, from 2:00 AM to 4:00 AM (UTC).';
    return $messages;
}

Show a custom message based on a date

Display a holiday greeting message.

add_filter('login_messages', 'show_holiday_message');
function show_holiday_message($messages) {
    if (date('m-d') == '12-25') {
        $messages .= '<br><em>Happy Holidays!</em> We wish you a Merry Christmas!';
    }
    return $messages;
}

Display a message for a specific user role

Show a message only to users with the ‘editor’ role.

add_filter('login_messages', 'show_editor_message');
function show_editor_message($messages) {
    $user = wp_get_current_user();
    if (in_array('editor', $user->roles)) {
        $messages .= '<br><em>Note to Editors:</em> Please review the new content guidelines.';
    }
    return $messages;
}