# Exclude Logos and Featured Images From Lazy Loading

> Adds the "no-lazyload" class (and matching skip attributes) to the site logo and the featured image of single posts, so Smush and other lazy-load plugins load them immediately and improve Largest Contentful Paint.

- Type: PHP
- Runs: Run everywhere
- Category: [Plugin Integrations](https://wpide.com/library/category/integrations/)
- Tags: smush, lazy-load, performance
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/smush-no-lazy-hero-images/

## Code

```php
add_filter( 'get_custom_logo_image_attributes', function ( $attr ) {
    $attr['class']         = trim( ( isset( $attr['class'] ) ? $attr['class'] : '' ) . ' no-lazyload skip-lazy' );
    $attr['loading']       = 'eager';
    $attr['data-no-lazy']  = '1';

    return $attr;
} );

add_filter( 'wp_get_attachment_image_attributes', function ( $attr, $attachment ) {
    if ( is_admin() || ! is_singular() || (int) get_post_thumbnail_id( get_queried_object_id() ) !== (int) $attachment->ID ) {
        return $attr;
    }

    $attr['class']        = trim( ( isset( $attr['class'] ) ? $attr['class'] : '' ) . ' no-lazyload skip-lazy' );
    $attr['loading']      = 'eager';
    $attr['data-no-lazy'] = '1';

    return $attr;
}, 10, 2 );
```

## Notes

Smush, WP Rocket and LiteSpeed all honour these markers; it also turns off native lazy loading for those images.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Exclude Logos and Featured Images From Lazy Loading" 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/
