wpseek.com
WordPress开发者和主题制作者的搜索引擎



wp_get_attachment_image_srcset › WordPress Function

Since4.4.0
已弃用n/a
wp_get_attachment_image_srcset ( $attachment_id, $size = 'medium', $image_meta = null )
参数: (3)
  • (int) $attachment_id Image attachment ID.
    Required: Yes
  • (string|int[]) $size Optional. Image size. Accepts any registered image size name, or an array of width and height values in pixels (in that order). Default 'medium'.
    Required: No
    默认: 'medium'
  • (array|null) $image_meta Optional. The image meta data as returned by 'wp_get_attachment_metadata()'. Default null.
    Required: No
    默认: null
查看:
返回:
  • (string|false) A 'srcset' value string or false.
定义在:
文档:

Retrieves the value for an image attachment's 'srcset' attribute.



源码

function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) {
	$image = wp_get_attachment_image_src( $attachment_id, $size );

	if ( ! $image ) {
		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 );
}