phpwordpresswordpress-login

Replace Default WordPress Logo with the Current Theme Logo in WordPress Login Page


I'm trying to replace the WordPress login logo with the active theme logo. The active theme is using the default "Customizer" options for the logo.

I'm using the following code

function my_custom_login_logo() {
echo '<style type="text/css">
h1 a {background-image:url(https://broproud.com/wp-content/uploads/2018/08/cropped-150-Width-Logo.png) !important; margin:0 auto;}
</style>';
}
add_filter( 'login_head', 'my_custom_login_logo' );

I know, I can change the logo, with this code, but how can I display the active theme logo automatically? What kind of function is required?


Solution

  • Please, try this one

    function my_custom_login_logo() {
        $logo_url = ( function_exists( 'the_custom_logo' ) && get_theme_mod( 'custom_logo' ) ) ? wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ), 'full' ) : false;
        $logo_url = ( $logo_url ) ? $logo_url[0] : generate_get_option( 'logo' );
    
        $logo_url = esc_url( apply_filters( 'generate_logo', $logo_url ) );
    
        ?>
        <style type="text/css">
            h1 a {
                background-image:url(<?php echo $logo_url ?>) !important; margin:0 auto;}
        </style>
        <?php
    }
    add_filter( 'login_head', 'my_custom_login_logo' );