login_message – Hook | Developer.WordPress.org (original) (raw)

Filters the message to display above the login form.

Parameters

$messagestring

Login message text.

More Information

The “login_message” filter is used to filter the message displayed on the WordPress login page above the login form. This filter can return HTML markup.

Source

View all references View on Trac View on GitHub

Used by Description
login_header()wp-login.php Outputs the login page header.

Changelog

Version Description
2.1.0 Introduced.

User Contributed Notes

  1. Skip to note 7 content
    Add additional message for wp-login.php
add_filter( 'login_message', 'wpdocs_sr_custom_login_message' );  
function wpdocs_sr_custom_login_message( $message ) {  
    <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>a</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mo>=</mo><mi>i</mi><mi>s</mi><mi>s</mi><mi>e</mi><mi>t</mi><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">action = isset( </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6595em;"></span><span class="mord mathnormal">a</span><span class="mord mathnormal">c</span><span class="mord mathnormal">t</span><span class="mord mathnormal">i</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">i</span><span class="mord mathnormal">sse</span><span class="mord mathnormal">t</span><span class="mopen">(</span></span></span></span>_REQUEST['action'] ) ? $_REQUEST['action'] : '';  
    $errors = new WP_Error();  
    if ( isset( $_GET['key'] ) ) {  
        $action = 'resetpass';  
    }  
    if ( isset( $_GET['checkemail'] ) ) {  
        $action = 'checkemail';  
    }  
    switch ( $action ):  
        case 'register':  
            $message .= '<p class="message">' . __( 'Show message before register form.', 'text_domain' ) . '</p>';  
            break;  
        case 'checkemail':  
            $message .= '<p class="message">' . __( 'Show message before after registration complete message.', 'text_domain' ) . '</p>';  
            break;  
        case 'lostpassword':  
            $message .= '<p class="message">' . __( 'Show message before lost password form.', 'text_domain' ) . '</p>';  
            break;  
        default:  
            // this message will show in login screen, before the login form.  
            $message .= '<p class="message">' . __( 'Show message before login form.', 'text_domain' ) . '</p>';  
            break;  
    endswitch;  
    return $message;  
}  
  1. Skip to note 8 content
    An example
function wpdocs_the_login_message( $message ) {  
    if ( empty( $message ) ) {  
        return '<p>Welcome to this site. Please log in to continue.</p>';  
    } else {  
        return $message;  
    }  
}  
add_filter( 'login_message', 'wpdocs_the_login_message' );  
  1. Skip to note 9 content
    A plugin can register as a content filter with the code:
add_filter( 'login_message', 'wpdocs_plugin_function_name' );  
  1. Skip to note 10 content
    (From Codex)
    Example:
function the_login_message( $message ) {  
    if ( empty($message) ){  
        return "<p>Welcome to this site. Please log in to continue</p>";  
    } else {  
        return $message;  
    }  
}  
add_filter( 'login_message', 'the_login_message' );  
  1. Skip to note 11 content
    Expanding upon Razon Komar Pal‘s code snippet.
    I found that there are a few other instances that you might wish to show a specific message or not show any additional messages if the provided one is great.
add_filter( 'login_message', function ( $message ) {  
    <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>a</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mo>=</mo><mi>i</mi><mi>s</mi><mi>s</mi><mi>e</mi><mi>t</mi><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">action = isset( </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6595em;"></span><span class="mord mathnormal">a</span><span class="mord mathnormal">c</span><span class="mord mathnormal">t</span><span class="mord mathnormal">i</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">i</span><span class="mord mathnormal">sse</span><span class="mord mathnormal">t</span><span class="mopen">(</span></span></span></span>_REQUEST['action'] ) ? $_REQUEST['action'] : '';  
    if ( isset( $_GET['key'] ) ) {  
        $action = 'resetpass';  
    }  
    if ( isset( $_GET['checkemail'] ) ) {  
        $action = 'checkemail';  
    }  
    if ( isset( $_GET['interim-login'] ) ) {  
        $action = 'interim-login';  
    }  
    switch ( $action ) {  
        case 'register':  
            // $message .= __( 'Show message before register form.', 'text_domain' );  
            break;  
        case 'checkemail':  
            // $message .= __( 'Show message before after registration complete message.', 'text_domain' );  
            break;  
        case 'lostpassword':  
            // $message .= __( 'Show message before lost password form.', 'text_domain' );  
            break;  
        case 'rp':  
            // $message .= __( 'Show message before reset password form.', 'text_domain' );  
            break;  
        case 'resetpass':  
            // $message .= __( 'Show message after reset password form.', 'text_domain' );  
            break;  
        case 'interim-login':  
            // $message .= __( 'Show message before interim login form.', 'text_domain' );  
            break;  
        default:  
            // $message .= __( 'Show message before login form.', 'text_domain' );  
            break;  
    }  
    return $message;  
} );  
  1. Skip to note 12 content