Closed azaozz closed 4 years ago
Looking at this again, code is good but wondering if this functionality should be added in the first place :)
It allows "searching" the content for any (opening) HTML tags, then runs a tag-specific filter on the found tags. General drawback is that it will only be used to find img
for now and eventually for iframes.
It may be useful in the future if there's an attribute we'd want to auto-add similarly to "loading", or perhaps to remove an attribute or a class name as a "last resort" fix in some cases. It may also be useful for some plugins as there will be only one preg_replace_callback()
, not several. But all of these cases are quite "theoretical" for now, perhaps best to add it when it's needed more.
@azaozz I think we can keep this simple for now and limited to img
tags (see #3). As long as the public interface we introduce (filters) is flexible for the future, we should be good. In other words, I think we should keep the wp_lazy_loading_enabled
contextual including a variable $tag_name
, while for now this would only ever be img
.
I think we can keep this simple for now...
Yeah, thinking the same. Can add the extended support when it's "really needed" :)
Makes the implementation a lot more flexible and easier to expand in the future.
wp_add_lazy_load_attributes()
. Introduces_wp_filter_html_tags()
that makes it possible to search for any tag, and fires a filter depending on the tag name.wp_get_tags_to_filter()
that has a filterable list of the default tags (currently onlyimg
).wp_add_lazy_loading_to_img_tags()
used with the new filterwp_filter_img_tags
fired when img tags are found in_wp_filter_html_tags()
.See https://github.com/WordPress/wp-lazy-loading/pull/4.