apply_filters( ‘max_srcset_image_width’, int $max_width, int[] $size_array )

Filters the maximum image width to be included in a ‘srcset’ attribute.


The maximum image width to be included in the 'srcset'. Default '2048'.
An array of requested width and height values.
  • int
    The width in pixels.
  • 1 int
    The height in pixels.


$max_srcset_image_width = apply_filters( 'max_srcset_image_width', 2048, $size_array );



User Contributed Notes

  1. Skip to note 7 content

    Increase the limit based on the size of the original.

    In this example, we’re going to change the maximum allowed image width to 2048px if the original image is wider than 800px.

    function custom_max_srcset_image_width( $max_width, $size_array ) {
        $width = $size_array[0];
        if ( $width > 800 ) {
            $max_width = 2048;
        return $max_width;
    add_filter( 'max_srcset_image_width', 'custom_max_srcset_image_width', 10, 2 );
  2. Skip to note 8 content

    Hey Joe, your notes were a big help! Just for clarification though, what is the $max_width variable? When using this it appears to be looking at screen size, similar to a media query. For example: if screen is wider than 800px, load in the largest registered image size that’s not wider than 2048px. I’m a little confused about the “if the original image is wider than 800px” part. How does the original image size factor into what image is chosen?

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