Modify the Login Logo & Image URL Link in WordPress

by Ataul Ghani

Disclosure

Most of the users want to change the WordPress login logo to their own custom logo. But a part of them use third party plugins. Now, this code will allow you to easily modify the WordPress Login page Logo as well as the href link and title text of this logo without using any third party plugins.


add_filter( 'login_headerurl', 'namespace_login_headerurl' );
/**
* Replaces the login header logo URL
*
* @param $url
*/
function namespace_login_headerurl( $url ) {
$url = home_url( '/' );
return $url;
}
add_filter( 'login_headertitle', 'namespace_login_headertitle' );
/**
* Replaces the login header logo title
*
* @param $title
*/
function namespace_login_headertitle( $title ) {
$title = get_bloginfo( 'name' );
return $title;
}
add_action( 'login_head', 'namespace_login_style' );
/**
* Replaces the login header logo
*/
function namespace_login_style() {
echo '<style>.login h1 a { background-image: url( ' . get_template_directory_uri() . '/images/logo.png ) !important; }</style>';
}

If you want to use the site logo to replace the login logo, you can use the following to dynamically pull that information.


function namespace_login_style() {
if( function_exists('get_custom_header') ){
$width = get_custom_header()->width;
$height = get_custom_header()->height;
} else {
$width = HEADER_IMAGE_WIDTH;
$height = HEADER_IMAGE_HEIGHT;
}
echo '<style>'.PHP_EOL;
echo '.login h1 a {'.PHP_EOL;
echo '  background-image: url( '; header_image(); echo ' ) !important; '.PHP_EOL;
echo '  width: '.$width.'px !important;'.PHP_EOL;
echo '  height: '.$height.'px !important;'.PHP_EOL;
echo '  background-size: '.$width.'px '.$height.'px !important;'.PHP_EOL;
echo '}'.PHP_EOL;
echo '</style>'.PHP_EOL;
}

Share on:

Disclosure: This post may contain affiliate links or paid partnerships. We may earn a commission if you click a link and make a purchase, at no extra cost to you. See our disclosure for more info.
Photo of author
Written by Ataul Ghani

3 thoughts on “Modify the Login Logo & Image URL Link in WordPress”

Leave a Comment