检索图像附件的’srcset’属性的值。
原型
wp_get_attachment_image_srcset( int $attachment_id, array|string $size = 'medium', array $image_meta = null )
参数
$attachment_id
(int)
(Required)
图片附件ID。
$size
(array|string)
(Optional)
图片尺寸。接受任何有效的图像大小,或以像素为单位的宽度和高度值数组(按此顺序)。
$image_meta
(array)
(Optional)
由’wp_get_attachment_metadata()‘返回的图像元数据。
返回值
(string|bool)
‘srcset’值字符串或false。
源文件
路径:wp-includes/media.php
<?php
...
function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) {
if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) {
return false;
}
if ( ! is_array( $image_meta ) ) {
$image_meta = wp_get_attachment_metadata( $attachment_id );
}
$image_src = $image[0];
$size_array = array(
absint( $image[1] ),
absint( $image[2] )
);
return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_get_attachment_image_srcset/