wp_calculate_image_srcset

SummerySummery

A helper function to calculate the image sources to include in a ‘srcset’ attribute.

Syntax

wp_calculate_image_srcset( int[] $size_array, string $image_src, array $image_meta, int $attachment_id )

ParametersParameters

$size_array

(int[]) (Required) An array of width and height values.

  • (int) The width in pixels.
  • '1'
    (int) The height in pixels.

$image_src

(string) (Required) The 'src' of the image.

$image_meta

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

$attachment_id

(int) (Optional) The image attachment ID. Default 0.

ReturnReturn

(string|bool) The 'srcset' attribute value. False on error or when only one source exists.

SourceSource

File: wp-includes/media.php


			

ChangelogChangelog

Changelog
Version Description
4.4.0 Introduced.
Scroll to Top