# Preload the Site Logo

> Preloads the logo set in the theme or Site Editor so it appears with the first paint of the header.

- Type: PHP
- Runs: Frontend only
- Category: [Performance](https://wpide.com/library/category/performance/)
- Tags: performance, images, logo
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/preload-site-logo/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Preload the Site Logo" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
