From 20087d795121459574279e8b2a01e274af06b263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Mon, 5 Aug 2024 09:38:02 -0400 Subject: [PATCH] remove loading lazy attribute on images excluded from lazyload --- inc/Dependencies/RocketLazyload/Image.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/inc/Dependencies/RocketLazyload/Image.php b/inc/Dependencies/RocketLazyload/Image.php index 5b4076bcc3..a1b8fe9cb3 100644 --- a/inc/Dependencies/RocketLazyload/Image.php +++ b/inc/Dependencies/RocketLazyload/Image.php @@ -30,9 +30,18 @@ public function lazyloadImages( $html, $buffer, $use_native = true ) { $images = array_unique( $images, SORT_REGULAR ); foreach ( $images as $image ) { - $image = $this->canLazyload( $image ); + $original_image = $image; + $image = $this->canLazyload( $image ); if ( ! $image ) { + $image_no_lazy = preg_replace( '/loading=["\']lazy["\']/i', '', $original_image ); + + if ( null === $image_no_lazy ) { + continue; + } + + $html = str_replace( $original_image, $image_no_lazy, $html ); + continue; }