How to Create a Custom Login Page in WordPress

Rebrand the WordPress login page without editing core files

The default login page at wp-login.php works fine, but the WordPress logo and the link to wordpress.org look strange on a client’s site. WordPress has hooks for the logo, its link and its title, and a hook to load your own stylesheet on the login screen, so nothing in core has to be touched.

Problem: The login page shows WordPress branding instead of the site’s own.

Solution: Use login_enqueue_scripts to replace the logo and load a stylesheet, and the login_headerurl and login_headertitle filters for the logo link and its title. Put the code into the theme’s functions.php or a small plugin.

Logo and stylesheet

The logo is a background image of the link inside #login h1, so it is replaced with CSS:

<?php
add_action( 'login_enqueue_scripts', 'ha_login_logo' );

function ha_login_logo() {
    $logo_url = get_stylesheet_directory_uri() . '/images/logo.png';
    ?>
    <style>
        #login h1 a {
            background-image: url( <?php echo esc_url( $logo_url ); ?> );
            background-size: contain;
            width: 200px;
            height: 60px;
        }
    </style>
    <?php
}

add_action( 'login_enqueue_scripts', 'ha_login_stylesheet' );

function ha_login_stylesheet() {
    wp_enqueue_style(
        'ha-login',
        get_stylesheet_directory_uri() . '/css/login.css',
        array(),
        wp_get_theme()->get( 'Version' )
    );
}

In login.css you can style the rest of the page: body.login for the background, #loginform for the form, .wp-core-ui .button-primary for the button.

Logo link and title

By default the logo links to wordpress.org and its title is “Powered by WordPress”:

<?php
add_filter( 'login_headerurl', function () {
    return home_url( '/' );
} );

add_filter( 'login_headertitle', function () {
    return get_bloginfo( 'name' );
} );

Redirect after login

Administrators go to the dashboard, everybody else to a page of the site:

<?php
add_filter( 'login_redirect', 'ha_login_redirect', 10, 3 );

function ha_login_redirect( $redirect_to, $requested_redirect_to, $user ) {
    if ( $user instanceof WP_User ) {
        return $user->has_cap( 'manage_options' ) ? admin_url() : home_url( '/account/' );
    }

    return $redirect_to;
}

The $user argument is a WP_Error when the login failed, which is why the type is checked.

Update (2019): WordPress 5.2 replaced login_headertitle with the new login_headertext filter, which sets the text of the logo link. The old filter still works but triggers a deprecation notice, so on 5.2 and later use login_headertext.

NOTE: These hooks change only the look of the page, not its address. Bots find wp-login.php anyway; for protection against password guessing you need rate limiting or two-factor authentication, not a new logo.