Preload the Site Logo
Preloads the logo set in the theme or Site Editor so it appears with the first paint of the header.
Opens WPIDE on
Code
add_filter( 'wp_preload_resources', function ( $resources ) {
$logo_id = (int) get_theme_mod( 'custom_logo' );
$logo_id = $logo_id ? $logo_id : (int) get_option( 'site_logo' );
$image = $logo_id ? wp_get_attachment_image_src( $logo_id, 'full' ) : false;
if ( $image ) {
$resources[] = array(
'href' => $image[0],
'as' => 'image',
'fetchpriority' => 'high',
);
}
return $resources;
} );
Notes
Best for logos that are images (PNG, JPG, WebP); inline SVG logos need no preloading.
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.