Custom WordPress Login Logo with Secure Optimization

wordpress logo change in login page

Enhance your WordPress login experience by replacing the default WordPress logo with your own website icon. This lightweight PHP snippet automatically loads your site favicon as the login logo while keeping performance in mind with transient caching.

The code also improves branding by redirecting the login logo to your homepage and displaying your website name as the logo title. It includes URL sanitization to reduce security risks and keeps the customization simple without adding any extra plugin.

function optimized_secure_login_logo() {
    // Speed optimization: Cache the favicon URL
    $favicon_url = get_transient('custom_login_favicon_url');

    if (false === $favicon_url) {
        $favicon_url = get_site_icon_url();
        set_transient('custom_login_favicon_url', $favicon_url, DAY_IN_SECONDS);
    }

    if ($favicon_url) {
        // Security: Sanitize the URL to prevent XSS attacks
        $clean_url = esc_url($favicon_url);
        
        echo '<style type="text/css">
            body.login h1 a {
                background-image: url(' . $clean_url . ') !important;
                height: 70px !important;
                width: 100% !important;
                background-size: contain !important;
                background-position: center bottom !important;
                background-repeat: no-repeat !important;
                padding-bottom: 10px !important;
            }
        </style>';
    }
}
add_action('login_enqueue_scripts', 'optimized_secure_login_logo');

// Improve branding: Change login logo URL and title
add_filter('login_headerurl', function() { return home_url(); });
add_filter('login_headertext', function() { return get_bloginfo('name'); });

Features:
✅ Replace default WordPress login logo automatically
✅ Uses your website icon for consistent branding
✅ Optimized with caching for better performance
✅ Sanitized URL handling for improved security
✅ No additional plugin required

A simple and efficient way to create a more professional WordPress login page with your own brand identity.

Share with your Friends

Facebook
X
LinkedIn
WhatsApp

Share with your Friends

Facebook
X
LinkedIn
WhatsApp

Latest Code Lab