Aleš Sýkora / November 6, 2020 / 2 comments
Change WordPress login logo with code
min read / WordPress / Share on: Twitter, LinkedIn, Facebook
Post summary: Need to change wordpress login logo? Use this code in custom plugin or in Code Snippets plugin. Change the background image url to your image and Link Title to your site name for example. Updated Change URL to home_url Deprecated
Need to change wordpress login logo? Use this code in custom plugin or in Code Snippets plugin. Change the background image url to your image and Link Title to your site name for example.
Updated
<?php
add_action('login_head', function () {
$custom_logo = "/wp-content/uploads/2023/06/spssecb-cz-logo-vector-color.svg"; // logo URL
$logo_width = '100%'; // Logo width
$logo_height = 'auto'; // Logo height
$bg_size = 'contain'; // Background size
printf(
'<style>.login h1 a {background-image:url(%1$s) !important; margin:0 auto; width: %2$s; height: %3$s; background-size: %4$s;}</style>',
$custom_logo,
$logo_width,
$logo_height,
$bg_size
);
});
// Change URL logo link
add_filter('login_headerurl', 'custom_login_logo_url');
function custom_login_logo_url() {
return 'https://www.spssecb.cz/'; // Změňte URL na svou
}
Change URL to home_url
// Change logo URL link to WordPress home_url()
add_filter('login_headerurl', 'custom_login_logo_url');
function custom_login_logo_url() {
return home_url();
}
Deprecated
//Custom logo change
function login_logo() { ?>
<style type="text/css">
#login h1 a, .login h1 a {
background-image: url(https://www.domain.com/wp-content/uploads/logo.svg);
}
</style>
<?php }
add_action( 'login_enqueue_scripts', 'login_logo' );
//Custom logo URL
function login_logo_url() {
return home_url();
}
add_filter( 'login_headerurl', 'login_logo_url' );
function login_logo_url_title() {
return 'Link title';
}
add_filter( 'login_headertitle', 'login_logo_url_title' );
Fuel my passion for writing with a beer🍺
Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻
pierre
Hi,
Very good, but how can I set the image size please?
Cheers
Aleš Sýkora
Hello Pierre, I have added one line of code to change the size.
height: 160px;