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

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

Parameters

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

Source

$image_edited = preg_match( '/-e[0-9]{13}/', wp_basename( $image_src ), $image_edit_hash );

Changelog

VersionDescription
4.4.0Introduced.

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.