wp_get_attachment_image_sizes

Advertisement

Summery Summery

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

Syntax Syntax

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

Parameters Parameters

$attachment_id

(Required) Image attachment ID.

$size

(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'

$image_meta

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

Default value: null

Return Return

(string|bool) A valid source size value for use in a 'sizes' attribute or false.

Source Source

File: wp-includes/media.php

	}

	$srcset = '';

	foreach ( $sources as $source ) {
		$srcset .= str_replace( ' ', '%20', $source['url'] ) . ' ' . $source['value'] . $source['descriptor'] . ', ';
	}

	return rtrim( $srcset, ', ' );
}

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

Advertisement

Changelog Changelog

Changelog
Version Description
4.4.0 Introduced.

See also See also

Advertisement

Leave a Reply