Skip to content
Snippet CSSphpwordpress php

How to Change the WordPress Login Logo

Learn how to change the WordPress login logo with PHP, link it to your homepage, and customize its accessible text without a plugin.

Updated

Change the WordPress Login Logo
/**
 * Replace the default WordPress login logo with a theme image.
 */
function wdg_custom_login_logo() {
    $logo_url = get_stylesheet_directory_uri() . '/assets/images/login-logo.png';

    $css = sprintf(
        'body.login #login h1 a {
            background-image: url("%s");
            background-repeat: no-repeat;
            background-position: center;
            background-size: contain;
            width: 100%%;
            height: 90px;
            margin-bottom: 24px;
        }',
        esc_url( $logo_url )
    );

    wp_add_inline_style( 'login', $css );
}
add_action( 'login_enqueue_scripts', 'wdg_custom_login_logo' );

/**
 * Make the login logo link to this website's homepage.
 *
 * @return string
 */
function wdg_custom_login_logo_url() {
    return home_url( '/' );
}
add_filter( 'login_headerurl', 'wdg_custom_login_logo_url' );

/**
 * Use the site name as accessible text for the login logo link.
 *
 * @return string
 */
function wdg_custom_login_logo_text() {
    return esc_html( get_bloginfo( 'name' ) );
}
add_filter( 'login_headertext', 'wdg_custom_login_logo_text' );

Introduction

The default WordPress login screen displays the WordPress logo above the login form. If you’re building a website for a client or want a consistent brand experience, you can replace that image with your own logo using a small PHP snippet.

This solution requires no additional plugin and also updates the logo’s link and accessible text.

What You’ll Build

You’ll customize the standard WordPress login screen so that:

  • Your brand logo appears instead of the WordPress logo.
  • Clicking the logo opens your site’s homepage.
  • The logo link has meaningful accessible text based on your site name.

The change affects the login screen, not the logo shown in your site’s header.

Before You Start

Prepare a logo with a transparent background, preferably in PNG or WebP format. A wide image around 240 × 90 pixels is a practical starting point; for sharper rendering, you can export a higher-resolution image with the same proportions.

Place the image in your active child theme at this path:

wp-content/themes/your-child-theme/assets/images/login-logo.png

Create the assets/images folders if they do not exist. Replace your-child-theme with your actual child-theme folder name. If you choose WebP or another filename, update the PHP code below to match it exactly.

The PHP Snippet

Copy the complete PHP implementation from the Primary Code section displayed at the top of this Snippet. Add it to the child theme’s functions.php file. The code is kept in the dedicated Primary Code field rather than repeated in the article body.

Important: If functions.php already begins with <?php, don’t add another opening PHP tag. Don’t edit WordPress core files or the parent theme directly.

How It Works

1. Load CSS Only on the Login Screen

The login_enqueue_scripts action runs when WordPress prepares the login page. Inside the callback, wp_add_inline_style( 'login', $css ) adds your CSS to WordPress’s existing login stylesheet.

This keeps the customization out of your public-facing theme stylesheets.

2. Find Your Logo Automatically

get_stylesheet_directory_uri() gets the URL of the active theme directory. When you use a child theme, it points to the child theme, making this path suitable for the image you uploaded.

esc_url() cleans the generated URL before it is inserted into the CSS.

3. Resize the Logo

The selector body.login #login h1 a targets the logo link above the login form. The CSS replaces its background image and positions it within a 90-pixel-high area.

background-size: contain keeps the logo’s proportions. You can adjust height: 90px to fit a taller or shorter logo. The 100%% in the PHP format string produces the CSS value 100% after sprintf() runs.

4. Update the Link and Text

  • login_headerurl changes the logo link to your site’s homepage using home_url( '/' ).
  • login_headertext sets the link’s accessible text to the site name. Using esc_html() ensures that name is safe to output as HTML text.

Test the Result

  1. Save your functions.php changes and confirm the logo file exists at the specified path.
  2. Open https://your-domain.com/wp-login.php (replace the domain with your own).
  3. Check that your custom image appears and is not stretched or clipped.
  4. Click the logo and confirm that it opens your homepage.
  5. Check the logo on a narrow/mobile viewport and verify that the login form remains usable.

Expected result: Your site’s logo appears above the login form instead of the WordPress logo, and its link opens the homepage.

Common Problems

The original WordPress logo is still visible. Double-check the image filename and child-theme folder, then clear any relevant cache. Another plugin or theme customization may be overriding the CSS.

The image is missing. Open the image URL directly in your browser to confirm it exists. Make sure that the path in the snippet matches the real file location.

The logo looks too small or too large. Adjust the height value and use an image with proportions that fit the available width. Avoid stretching the image by specifying conflicting fixed dimensions.

The customization disappeared after switching themes. This version deliberately loads the image from the active theme. For a theme-independent solution, move the customization to a site-specific plugin and use an image URL that does not depend on the theme.

Important Notes

  • Changing the logo here does not modify your site’s Appearance → Customize / Site Editor logo setting.
  • The snippet does not change authentication, passwords, or login security.
  • Use a child theme or custom plugin so updates to the parent theme do not overwrite your changes.
  • WordPress’s older login_headertitle filter is deprecated; login_headertext is the correct filter for modern WordPress.

Conclusion

With the login_enqueue_scripts, login_headerurl, and login_headertext hooks, you can customize your WordPress login branding using a small amount of PHP and CSS—without changing WordPress core files.

Official WordPress References