wp_img_tag_add_srcset_and_sizes_attr
函数
wp_img_tag_add_srcset_and_sizes_attr ( $image, $context, $attachment_id )
- 参数
-
-
(string)
$image
The HTML `img` tag where the attribute should be added.- Required: 是
-
(string)
$context
Additional context to pass to the filters.- Required: 是
-
(int)
$attachment_id
Image attachment ID.- Required: 是
-
(string)
- 返回值
-
- (string) Converted ‘img’ element with ‘loading’ attribute added.
- 定义位置
-
-
wp-includes/media.php
, line 2044
-
wp-includes/media.php
- 引入
- 5.5.0
- 弃用
- –
Adds `srcset` and `sizes` attributes to an existing `img` HTML tag.
function wp_img_tag_add_srcset_and_sizes_attr( $image, $context, $attachment_id ) { /** * 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. * * @since 5.5.0 * * @param bool $value The filtered value, defaults to `true`. * @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. */ $add = apply_filters( 'wp_img_tag_add_srcset_and_sizes_attr', true, $image, $context, $attachment_id ); if ( true === $add ) { $image_meta = wp_get_attachment_metadata( $attachment_id ); return wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ); } return $image; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。