Skip to content

Fix matching of HTML attributes in filter_images() #54

Description

@jan-san

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 issue was reported on wordpress.org: https://wordpress.org/support/topic/broken-image-10/

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtopic:imgIssues related to the lazy loading of img tags

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions