apply_filters( 'wp_calculate_image_srcset', array $sources, array $size_array, string $image_src, array $image_meta, int $attachment_id )

Filters an image’s ‘srcset’ sources.

Description Description

Parameters Parameters


(array) One or more arrays of source data to include in the 'srcset'.

  • 'width'
    • 'url'
      (string) The URL of an image source.
    • 'descriptor'
      (string) The descriptor type used in the image candidate string, either 'w' or 'x'.
    • 'value'
      (int) The source width if paired with a 'w' descriptor, or a pixel density value if paired with an 'x' descriptor.


(array) Array of width and height values in pixels (in that order).


(string) The 'src' of the image.


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


(int) Image attachment ID or 0.

Top ↑

Source Source

File: wp-includes/media.php

View on Trac

Top ↑

Changelog Changelog

Version Description
4.4.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by axew3
    function abc_custom_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ){
       $w = get_custom_header()->width;
    // srcset val
          $sources[$w] = array(
                 'url'        => 'myfolder/myimage.jpg',
                 'descriptor' => 'w',
                 'value'      => $w,
             return $sources;
       add_filter( 'wp_calculate_image_srcset', 'abc_custom_image_srcset', 10, 5 );

You must log in before being able to contribute a note or feedback.