Using WordPress ‘login_message’ PHP filter

The login_message WordPress PHP Filter allows you to modify the message displayed above the login form.

Usage

add_filter('login_message', 'your_custom_function_name');
function your_custom_function_name($message) {
    // your custom code here
    return $message;
}

Parameters

  • $message (string): The login message text to be displayed.

More information

See WordPress Developer Resources: login_message

Examples

Add a custom welcome message

Add a custom welcome message above the login form.

add_filter('login_message', 'custom_welcome_message');
function custom_welcome_message($message) {
    $message = "<p>Welcome to our website! Please log in to continue.</p>";
    return $message;
}

Display a maintenance notice

Show a maintenance notice above the login form.

add_filter('login_message', 'maintenance_notice');
function maintenance_notice($message) {
    $message = "<p>**Notice**: We're performing maintenance. You may experience some issues while logging in.</p>";
    return $message;
}

Show a promotional message

Display a promotional message above the login form.

add_filter('login_message', 'promotional_message');
function promotional_message($message) {
    $message = "<p>Don't forget to check our **Spring Sale** after logging in!</p>";
    return $message;
}

Display security tips

Show security tips above the login form.

add_filter('login_message', 'security_tips_message');
function security_tips_message($message) {
    $message = "<p>**Security Tip**: Always use strong, unique passwords to keep your account safe.</p>";
    return $message;
}

Show a custom error message

Display a custom error message above the login form when there’s an error.

add_filter('login_message', 'custom_error_message');
function custom_error_message($message) {
    if (isset($_GET['error']) && $_GET['error'] == 'invalid_login') {
        $message = "<p>**Error**: Invalid username or password. Please try again.</p>";
    }
    return $message;
}