-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
Describe the bug
Hi, I add the attribute data-no-lazy on featured image of blog single article. But it's still lazy loaded
To Reproduce
In your child theme add this file 'article.php':
<?php
class Ido_Article {
public function __construct() {
add_filter('wp_get_attachment_image_attributes', [$this, 'exclude_lazy_loading_for_post_images'], 5, 3);
}
public function exclude_lazy_loading_for_post_images($attr, $attachment, $size) {
// Vérifie si on est sur une page d'article de blog (post type 'post')
if (is_single() && get_post_type() === 'post') {
// Vérifie si l'image a la classe 'attachment-full'
if (isset($attr['class']) && strpos($attr['class'], 'attachment-full') !== false) {
var_dump("apply no lazy");
// Ajoute l'attribut data-no-lazy="1"
$attr['data-no-lazy'] = '1';
}
}
return $attr;
}
}
- don't forget to include and instantiate the class in your function.php
Expected behavior
I expect to miss the loading="lazy" on my featured image
Screenshots
https://i.imgur.com/j5BItzb.png
url : https://stg-idonim-staging.kinsta.cloud/les-kits-soutien-gorges/
PS
I was thinking that above viewport line, pictures was automatically excluded of lazy loading
Desktop (please complete the following information):
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
Smartphone (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
Additional context
Add any other context about the problem here.
s
Metadata
Metadata
Assignees
Labels
No labels