How to Change the Login Logo in WordPress

Home » Snippets » How to Change the Login Logo in WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Are you tired of the default login logo on your WordPress site? Do you want to make your login page more professional or align it with your brand? Well, you’re in luck! In this article, we will show you how to easily change the login logo in WordPress. With a few simple steps, you can customize the login page and make it more visually appealing to your visitors. So, let’s dive in and give your login page a fresh new look!

					function wpturbo_change_login_logo() {
    echo '<style type="text/css">
        h1 a {
            background-image: url(' . get_stylesheet_directory_uri() . '/images/login-logo.png) !important;
            background-size: contain;
            width: 100%;
            height: 100px;
        }
    </style>';
}
add_action('login_head', 'wpturbo_change_login_logo');
				

The code snippet provided allows you to change the default WordPress login logo to a custom one. This can be useful if you want to customize the login page to match the branding of your website or client's website.

The wpturbo_change_login_logo() function is responsible for displaying the custom login logo. Inside this function, we use the echo statement to output some CSS code. This CSS code is enclosed in <style> tags to define a new inline style.

Within the CSS code, we target the h1 a selector, which represents the anchor tag within the <h1> element on the WordPress login page. This is the element that contains the default WordPress login logo.

The first line within the CSS code sets the background image of the <h1> anchor tag using the background-image property. We use the get_stylesheet_directory_uri() function to retrieve the URL of the current stylesheet directory. This allows us to dynamically generate the URL of the custom login logo image. In this example, we assume that the custom login logo image is located in the "images" folder within the current theme directory.

The background-size property is set to "contain" to ensure that the custom logo image fits within the anchor tag without being cropped or distorted.

We also set the width of the anchor tag to 100% and the height to 100px. This ensures that the custom login logo is displayed properly and doesn't overlap with other elements on the login page.

Finally, we hook the wpturbo_change_login_logo() function into the login_head action. This action is triggered when the login page is loaded, allowing us to inject our custom CSS code to change the login logo.

Register an account to save your snippets or go Pro to get more features.