A WordPress-centric search engine for devs and theme authors



wp_get_attachment_image_sizes ›

Since4.4.0
Deprecatedn/a
wp_get_attachment_image_sizes ( $attachment_id, $size = 'medium', $image_meta = null )
Parameters: (3)
  • (int) $attachment_id Image attachment ID.
    Required: Yes
  • (array|string) $size Optional. Image size. Accepts any valid image size, or an array of width and height values in pixels (in that order). Default 'medium'.
    Required: No
    Default: 'medium'
  • (array) $image_meta Optional. The image meta data as returned by 'wp_get_attachment_metadata()'. Default null.
    Required: No
    Default: null
See:
Returns:
  • (string|bool) A valid source size value for use in a 'sizes' attribute or false.
Defined at:
Codex:

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



Source

function wp_get_attachment_image_sizes( $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_sizes( $size_array, $image_src, $image_meta, $attachment_id );
}