Skip to content

Instantly share code, notes, and snippets.

@cre8tivediva
Created October 14, 2023 14:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cre8tivediva/4d74dca6c6647b812d13e91488a85fc6 to your computer and use it in GitHub Desktop.
Save cre8tivediva/4d74dca6c6647b812d13e91488a85fc6 to your computer and use it in GitHub Desktop.
Change the logo and url on the login page
// Update the login logo with the custom header image
function custom_login_logo() {
// Get the header image from the Customizer
$header_image = get_header_image();
if (!$header_image) {
return;
}
// Styles to replace the WordPress logo with the custom header image
$custom_css = sprintf(
'.login h1 a {
background-image: url(%s);
background-size: contain;
width: 100%%;
height: 120px;
display: block;
margin-bottom: 10px;
}',
esc_url($header_image)
);
echo '<style type="text/css">' . $custom_css . '</style>';
}
add_action('login_head', 'custom_login_logo');
// Change the URL of the login logo to the site's homepage
function custom_login_logo_url() {
return home_url();
}
add_filter('login_headerurl', 'custom_login_logo_url');
// Change the title attribute of the login logo link
function custom_login_logo_url_title() {
return get_bloginfo('name', 'display');
}
add_filter('login_headertext', 'custom_login_logo_url_title');
@gugaalves
Copy link

gugaalves commented Oct 14, 2023

If you're using a theme that registers a new custom logo area, you can use that function to get it:

https://developer.wordpress.org/themes/functionality/custom-logo/#displaying-the-custom-logo-in-your-theme

@gugaalves
Copy link

gugaalves commented Oct 14, 2023

`function custom_login_logo() {
// Get logo
if ( has_custom_logo() ) {
$custom_logo_id = get_theme_mod( 'custom_logo' );
$header_image = wp_get_attachment_image_src( $custom_logo_id , 'full' );
$logo = $header_image[0];
} else {
$logo = get_header_image();
}

if (!$logo) {
    return;
}

// Styles to replace the WordPress logo with the custom header image
$custom_css =
    '.login h1 a {
        background-image: url('. esc_url($logo) .');
        background-size: contain;
        width: 100%;
        height: 120px;
        display: block;
        margin-bottom: 10px;
    }';

echo '<style type="text/css">' . $custom_css . '</style>';

}`

@cre8tivediva
Copy link
Author

Thank you and thank you for commenting here too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment