WPDev.one
Core Function
View Source on Trac ↗

wp_calculate_image_srcset()

wp_calculate_image_srcset( mixed $size_array, mixed $image_src, mixed $image_meta, mixed $attachment_id = 0 )

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

Parameters 3 required

Name / Type Description
int[]

$size_array { An array of width and height values.

Required
$image_src
string

The 'src' of the image.

Required
$image_meta
array

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

Required
$attachment_id
int

Optional. The image attachment ID. Default 0.

Return Value

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

Function Information

Since Version
4.4.0
Source File
wp-includes/media.php
Advertisement