Using WordPress ‘login_header’ PHP action

The login_header WordPress PHP action fires in the login page header after the body tag is opened.

Usage

add_action('login_header', 'your_custom_function');
function your_custom_function() {
    // your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: login_header

Examples

Add a custom message to the login header

Add a custom message to the login header for branding or announcements.

add_action('login_header', 'add_custom_message_to_login_header');
function add_custom_message_to_login_header() {
    echo '<div class="custom-message">Welcome to our awesome website!</div>';
}

Add a custom logo to the login header

Replace the default WordPress logo with a custom logo on the login page.

add_action('login_header', 'add_custom_logo_to_login_header');
function add_custom_logo_to_login_header() {
    echo '<div class="custom-logo"><img src="/path/to/your/logo.png" alt="Your Logo"></div>';
}

Add custom styles to the login header

Inject custom CSS to style the login page.

add_action('login_header', 'add_custom_styles_to_login_header');
function add_custom_styles_to_login_header() {
    echo '<style>.login h1 { display: none; }</style>';
}

Add a custom JavaScript to the login header

Inject custom JavaScript to modify the login page behavior.

add_action('login_header', 'add_custom_js_to_login_header');
function add_custom_js_to_login_header() {
    echo '<script>console.log("Custom JavaScript loaded.");</script>';
}

Add an additional login security feature

Add a custom security feature, like a Google reCAPTCHA, to the login page.

add_action('login_header', 'add_recaptcha_to_login_header');
function add_recaptcha_to_login_header() {
    echo '<script src="https://www.google.com/recaptcha/api.js" async defer></script>';
    echo '<div class="g-recaptcha" data-sitekey="your-recaptcha-site-key"></div>';
}