Summery Summery

Retrieves the value for an image attachment’s ‘srcset’ attribute.

Syntax Syntax

wp_get_attachment_image_srcset( int $attachment_id, array|string $size = 'medium', array $image_meta = null )

Parameters Parameters


(Required) Image attachment ID.


(Optional) Image size. Accepts any valid image size, or an array of width and height values in pixels (in that order). Default 'medium'.

Default value: 'medium'


(Optional) The image meta data as returned by 'wp_get_attachment_metadata()'.

Default value: null

Return Return

(string|bool) A 'srcset' value string or false.

Source Source

File: wp-includes/media.php

	} elseif ( ! empty( $image_meta['sizes'][ $size_name ] ) ) {
		return array(
			absint( $image_meta['sizes'][ $size_name ]['width'] ),
			absint( $image_meta['sizes'][ $size_name ]['height'] ),

	return false;

 * Retrieves the value for an image attachment's 'srcset' attribute.
 * @since 4.4.0
 * @see wp_calculate_image_srcset()
 * @param int          $attachment_id Image attachment ID.


Changelog Changelog

Version Description
4.4.0 Introduced.

See also See also


Leave a Reply