Using WordPress ‘login_head’ PHP action

The login_head WordPress PHP action allows you to insert custom code into the <head> section of the WordPress login page.

Usage

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

Parameters

  • None

More information

See WordPress Developer Resources: login_head

Examples

Add a custom CSS file to the login page

This example adds a custom CSS file named customlogin.css to the login page.

function childtheme_custom_login() {
    echo '<link rel="stylesheet" type="text/css" href="' . get_bloginfo('stylesheet_directory') . '/customlogin.css" />';
}
add_action('login_head', 'childtheme_custom_login');

Change the background color of the login page

This example changes the background color of the login page to red.

function change_login_background() {
    echo '<style>html { background-color: #f00; }</style>';
}
add_action('login_head', 'change_login_background');

This example replaces the default WordPress logo with a custom logo from your theme directory.

function my_custom_login_logo() {
    echo '<style type="text/css">
        h1 a { background-image:url('.get_stylesheet_directory_uri().'/images/login.png) !important;
        height: 120px !important; width: 410px !important; margin-left: -40px;}
    </style>';
}
add_action('login_head', 'my_custom_login_logo');

Add custom JavaScript to the login page

This example adds custom JavaScript code to the login page.

function custom_login_js() {
    echo '<script>console.log("Hello from custom login JS!");</script>';
}
add_action('login_head', 'custom_login_js');

Add a favicon to the login page

This example adds a custom favicon to the login page.

function custom_login_favicon() {
    echo '<link rel="shortcut icon" href="'.get_stylesheet_directory_uri().'/images/favicon.ico" />';
}
add_action('login_head', 'custom_login_favicon');