Use the Main Site's Icon on Sites Without One
Makes subsites that have no Site Icon of their own show the main site's favicon and app icon, so every browser tab carries your brand.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
add_filter( 'get_site_icon_url', function ( $url, $size, $blog_id ) {
$main = get_main_site_id();
if ( $url || (int) $blog_id === $main || ( ! $blog_id && is_main_site() ) ) {
return $url;
}
$key = 'wpide_main_icon_' . (int) $size;
$cached = wp_cache_get( $key, 'wpide' );
if ( false === $cached ) {
$icon_id = (int) get_blog_option( $main, 'site_icon' );
$cached = '';
if ( $icon_id ) {
switch_to_blog( $main );
$cached = (string) wp_get_attachment_image_url( $icon_id, array( $size, $size ) );
restore_current_blog();
}
wp_cache_set( $key, $cached, 'wpide', HOUR_IN_SECONDS );
}
return $cached ? $cached : $url;
}, 10, 3 );
Notes
Sites that upload their own icon keep it.
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.