Determines whether to add the loading
attribute to the specified tag in the specified context.
Parameters
$tag_name
stringrequired- The tag name.
$context
stringrequired- Additional context, like the current filter name or the function name from where this was called.
Source
return $image;
}
/**
* Determines whether to add the `loading` attribute to the specified tag in the specified context.
*
* @since 5.5.0
* @since 5.7.0 Now returns `true` by default for `iframe` tags.
*
* @param string $tag_name The tag name.
* @param string $context Additional context, like the current filter name
* or the function name from where this was called.
* @return bool Whether to add the attribute.
*/
function wp_lazy_loading_enabled( $tag_name, $context ) {
/*
* By default add to all 'img' and 'iframe' tags.
* See https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-loading
* See https://html.spec.whatwg.org/multipage/iframe-embed-object.html#attr-iframe-loading
wp_lazy_loading_enabled
returns true for alltags, which is every time this function is called by default. Hooking into the
wp_lazy_loading_enabled
filter is the primary way of enabling or disabling this feature, however it does not readily allow this to be enabled or disabled for specific attachments or mime-types.1. To change how this feature works for specific attachments, the ‘loading’ attribute can be supplied to the
wp_get_attachment_image
function, or you can modify or remove the attribute using thewp_get_attachment_image_attributes
filter.Or
2. To change how this works for specific avatars, you can either redefine the
get_avatar
function, supply the ‘loading’ attribute within the ‘extra_attr’ argument, or replace the HTML using theget_avatar
filter.3.
the_content
,the_excerpt
andwidget_text_filters
will call thewp_filter_content_tags
filter on the content, which will also add the ‘loading’ attribute to image tags. To adjust this, thewp_img_tag_add_loading_attr
filter can be used to manage the ‘loading’ attribute on a tag by tag basis.