apply_filters( 'wp_calculate_image_srcset', array $sources, array $size_array, string $image_src, array $image_meta, int $attachment_id )
- Since
- 4.4.0
Filters an image's 'srcset' sources.
Compatibility
- WordPress
- since 4.4.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Parameters
$sourcesarray- { One or more arrays of source data to include in the 'srcset'.
@type array $width { @type string $url The URL of an image source.
@type string $descriptor The descriptor type used in the image candidate string, either 'w' or 'x'.
@type int $value The source width if paired with a 'w' descriptor, or a pixel density value if paired with an 'x' descriptor.
} }$widtharray@type string $url The URL of an image source.$descriptorstringThe descriptor type used in the image candidate string, either 'w' or 'x'.$valueintThe source width if paired with a 'w' descriptor, or a pixel density value if paired with an 'x' descriptor.
$size_arrayarray- { An array of requested width and height values.
@type int $0 The width in pixels.
@type int $1 The height in pixels.
}$0intThe width in pixels.$1intThe height in pixels.
$image_srcstring- The 'src' of the image.
$image_metaarray- The image meta data as returned by 'wp_get_attachment_metadata()'.
$attachment_idint- Image attachment ID or 0.
Where this hook fires · 1
wp-includes/media.php:1517wp_calculate_image_srcset()
Source code
* @type int $1 The height in pixels. * } * @param string $image_src The 'src' of the image. * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'. * @param int $attachment_id Image attachment ID or 0. */ $sources = apply_filters( 'wp_calculate_image_srcset', $sources, $size_array, $image_src, $image_meta, $attachment_id ); // Only return a 'srcset' value if there is more than one source. if ( ! $src_matched || ! is_array( $sources ) || count( $sources ) < 2 ) { return false; }Changelog
Introduced in 4.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
- Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.