Your logo on the login page
Shows the logo set in your theme (Site Logo or Customizer > Site Identity) on the login page instead of the WordPress logo.
<?php
add_action(
'login_enqueue_scripts',
static function () {
$logo_id = (int) get_theme_mod( 'custom_logo' );
if ( ! $logo_id ) {
$logo_id = (int) get_option( 'site_logo' ); // Block themes.
}
$logo = $logo_id ? wp_get_attachment_image_src( $logo_id, 'medium' ) : false;
if ( ! $logo || empty( $logo[1] ) ) {
return;
}
$height = (int) min( 120, round( 320 * $logo[2] / $logo[1] ) );
wp_add_inline_style(
'login',
sprintf(
'.login h1 a{background-image:url("%s");background-size:contain;background-position:center;width:100%%;max-width:320px;height:%dpx;}',
esc_url_raw( $logo[0] ),
max( 40, $height )
)
);
}
);
Good to know
Works well together with “Login logo links to your site”.
In these packs
- Admin and login: Your branding on the login page, a tidier admin, and handy extras such as duplicating posts.