wp_img_tag_add_srcset_and_sizes_attr
Filters whether to add the srcset and sizes HTML attributes to the img tag. Default true.
Returning anything else than true will not add the attributes.
Usage
add_filter( 'wp_img_tag_add_srcset_and_sizes_attr', 'wp_kama_img_tag_add_srcset_and_sizes_attr_filter', 10, 4 );
/**
* Function for `wp_img_tag_add_srcset_and_sizes_attr` filter-hook.
*
* @param bool $value The filtered value.
* @param string $image The HTML `img` tag where the attribute should be added.
* @param string $context Additional context about how the function was called or where the img tag is.
* @param int $attachment_id The image attachment ID.
*
* @return bool
*/
function wp_kama_img_tag_add_srcset_and_sizes_attr_filter( $value, $image, $context, $attachment_id ){
// filter...
return $value;
}
- $value(true|false)
- The filtered value.
Default:true - $image(string)
- The HTML
imgtag where the attribute should be added. - $context(string)
- Additional context about how the function was called or where the img tag is.
- $attachment_id(int)
- The image attachment ID.
Changelog
| Since 5.5.0 | Introduced. |
Where the hook is called
wp_img_tag_add_srcset_and_sizes_attr
wp-includes/media.php 2337
$add = apply_filters( 'wp_img_tag_add_srcset_and_sizes_attr', true, $image, $context, $attachment_id );