diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index b9b98dd..0e02897 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -33,6 +33,9 @@ function test_wp_lazy_load_content_media() { // The following should not be modified because there already is a 'loading' attribute. $img_eager = str_replace( ' />', ' loading="eager" />', $img ); + // The following should not be modified either, because 'skip-lazy' is present. + $img_skiplazy = str_replace( 'class="', 'class="skip-lazy ', $img ); + $content = '
Image, standard.
%1$s @@ -46,11 +49,14 @@ function test_wp_lazy_load_content_media() {Image, with pre-existing "loading" attribute.
%5$s +Image, with "skip-lazy" set, not to be modified.
+ %6$s +Iframe, standard. Should not be modified by default.
%4$s'; - $content_unfiltered = sprintf( $content, $img, $img_xhtml, $img_html5, $iframe, $img_eager ); - $content_filtered = sprintf( $content, $lazy_img, $lazy_img_xhtml, $lazy_img_html5, $iframe, $img_eager ); + $content_unfiltered = sprintf( $content, $img, $img_xhtml, $img_html5, $iframe, $img_eager, $img_skiplazy ); + $content_filtered = sprintf( $content, $lazy_img, $lazy_img_xhtml, $lazy_img_html5, $iframe, $img_eager, $img_skiplazy ); $this->assertSame( $content_filtered, wp_add_lazy_load_attributes( $content_unfiltered ) ); } diff --git a/wp-lazy-loading.php b/wp-lazy-loading.php index 0a3495d..b79e02f 100644 --- a/wp-lazy-loading.php +++ b/wp-lazy-loading.php @@ -62,7 +62,7 @@ function _wp_lazy_loading_initialize_filters() { * @return string Modified tag. */ function _wp_lazy_loading_add_attribute_to_avatar( $avatar ) { - if ( in_array( 'img', wp_get_lazy_load_tags(), true ) && false === strpos( $avatar, ' loading=' ) ) { + if ( in_array( 'img', wp_get_lazy_load_tags(), true ) && false === strpos( $avatar, ' loading=' ) && false === strpos( $avatar, 'skip-lazy' ) ) { $avatar = str_replace( '