Network-Wide Login Logo From the Main Site
Shows the main site's custom logo on the login screen of every site in the network, linked to the site being logged in to.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
add_action( 'login_enqueue_scripts', function () {
$main = get_main_site_id();
$mods = get_blog_option( $main, 'theme_mods_' . get_blog_option( $main, 'stylesheet' ) );
$logo_id = is_array( $mods ) && ! empty( $mods['custom_logo'] ) ? (int) $mods['custom_logo'] : 0;
if ( ! $logo_id ) {
return;
}
switch_to_blog( $main );
$src = wp_get_attachment_image_src( $logo_id, 'medium' );
restore_current_blog();
if ( ! $src ) {
return;
}
$width = min( 320, (int) $src[1] );
$height = $src[1] ? (int) round( $src[2] * $width / $src[1] ) : 84;
printf(
'<style>.login h1 a{background-image:url(%1$s);background-size:contain;background-position:center;width:%2$dpx;height:%3$dpx;max-width:100%%}</style>',
esc_url( $src[0] ),
(int) $width,
(int) $height
);
} );
add_filter( 'login_headerurl', function () {
return home_url( '/' );
} );
add_filter( 'login_headertext', function () {
return get_bloginfo( 'name' );
} );
Notes
Uses the main site's Customizer logo (custom_logo); set one there first.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.