Created
October 14, 2023 14:00
-
-
Save cre8tivediva/4d74dca6c6647b812d13e91488a85fc6 to your computer and use it in GitHub Desktop.
Change the logo and url on the login page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); |
`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>';
}`
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
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