Function: wp_calculate_image_sizes

wp_calculate_image_sizes( array | string $size, string $image_src, array $image_meta, integer $attachment_id )

Creates a 'sizes' attribute value for an image.

Parameters

Name Type(s) Default Value Description
$size array | string

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

$image_src string null

Optional. The URL to the image file. Default null.

$image_meta array null

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

$attachment_id integer

Optional. Image attachment ID. Either $image_meta or $attachment_id is needed when using the image size name as argument for $size. Default 0.

Returns

string | boolean

A valid source size value for use in a 'sizes' attribute or false.

WordPress Developer Newsletter

Stay on top of the latest WordPress API changes, developer tool updates, security alerts and more.