Skip to content
  • Log In
  • Register
WordPress.org
  • News
  • Download & Extend
    • Get WordPress
    • Themes
    • Patterns
    • Plugins
    • Mobile
    • Hosting
    • Openverse ↗︎
  • Learn
    • Learn WordPress
    • Documentation
    • Forums
    • Developers
    • WordPress.tv ↗︎
  • Community
    • Make WordPress
    • Photo Directory
    • Five for the Future
    • WordCamp ↗︎
    • Meetups ↗︎
    • Job Board ↗︎
  • About
    • About WordPress
    • Showcase
    • Enterprise
    • Gutenberg ↗︎
    • WordPress Swag Store ↗︎
  • Get WordPress
Get WordPress

Developer Resources

Browse: Home / Reference / Hooks / login_head

do_action( 'login_head' )

Fires in the login page header after scripts are enqueued.

Contents

  • More Information
  • Source
  • Related
    • Used By
  • Changelog
  • User Contributed Notes

More Information

This filter can be used to add anything to the <head> section on the login page.

You can customise the login form using login_head fairly easily.

Add the following code to functions.php in your theme:

// custom login for theme
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');

This has the effect of adding a reference to a stylesheet to your login form.

You will then need to add a stylesheet called customlogin.css to your theme directory.

For testing purposes, this should start you off:

html {
background-color: #f00;
}

This should produce a login background.

Here we replace the standard WordPress logo with our logo, taken from our theme (this uses get_stylesheet_directory_uri to work with child themes):

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');

To set the URL of the login icon’s link, see login_headerurl


Top ↑

Source

File: wp-login.php. View all references

do_action( 'login_head' );

View on Trac View on GitHub


Top ↑

Related

Top ↑

Used By

Used By
Used By Description
login_header() wp-login.php

Outputs the login page header.


Top ↑

Changelog

Changelog
Version Description
2.1.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note
    Contributed by tarhe — 3 years ago

    More Information
    login_head handles authentication, registering, resetting passwords, forgot password,
    and other user handling.

    The login_head filter can be used to filter the logo image on the WordPress login page. By default this logo is of WordPress.

    Note: this is not the only possible use of this filter. It can be used to add anything to the section on the login page.

    Basic Examples
    Where “wpdocs_custom_function_name” is the function to be called when the content is being retrieved.

    add_filter( 'login_head', 'wpdocs_custom_function_name' );

    In the below example the default logo is changed to custom logo, using CSS.

    function wpdocs_my_custom_login_logo() {
        echo '<style type="text/css">
    	h1 a { background-image: url(http://example.com/your-logo.png) !important; margin: 0 auto; }
    	</style>';
    }
    add_filter( 'login_head', 'wpdocs_my_custom_login_logo' );

    To validate the login details before user logins, you can use the below function:
    (p.s. At first, you may have inserted some extra fields using ‘login_form’ action hook.)

    function wpdocs_ref_access() {
        global $error;
        if ( empty( $_POST['custom_field_name'] ) ) {
            $error  = 'Restricted area, please login to continue.';
        }
    }
    add_action( 'login_head', 'wpdocs_ref_access' );
    Log in to add feedback

You must log in before being able to contribute a note or feedback.

  • About
  • News
  • Hosting
  • Donate
  • Swag
  • Documentation
  • Developers
  • Get Involved
  • Learn
  • Showcase
  • Plugins
  • Themes
  • Patterns
  • WordCamp
  • WordPress.TV
  • BuddyPress
  • bbPress
  • WordPress.com
  • Matt
  • Privacy
  • Public Code
WordPress.org
WordPress.org
  • Visit our Facebook page
  • Visit our Twitter account
  • Visit our Instagram account
  • Visit our LinkedIn account
  • Visit our YouTube channel
Code is Poetry

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.