The code used to replace srcset and sizes attributes is overly simple and can cause issues like replacing parts of the src or other unrelated attributes:
// also replace the srcset (responsive images)
$replaceHTML = str_replace( 'srcset', 'data-lazy-srcset', $replaceHTML );
// replace sizes to avoid w3c errors for missing srcset
$replaceHTML = str_replace( 'sizes', 'data-lazy-sizes', $replaceHTML );
To fix this, we need to implement a proper parsing of the HTML tag and its attributes.
The code used to replace
srcset
andsizes
attributes is overly simple and can cause issues like replacing parts of thesrc
or other unrelated attributes:To fix this, we need to implement a proper parsing of the HTML tag and its attributes.
The issue was reported on wordpress.org: https://wordpress.org/support/topic/broken-image-10/