Filters the maximum image width to be included in a ‘srcset’ attribute.
Parameters
$max_width
int- The maximum image width to be included in the
'srcset'
. Default'2048'
. $size_array
int[]- An array of requested width and height values.
0
intThe width in pixels.1
intThe height in pixels.
Source
$image_edited = preg_match( '/-e[0-9]{13}/', wp_basename( $image_src ), $image_edit_hash );
Changelog
Version | Description |
---|---|
4.4.0 | Introduced. |
Remove the 1600px limit for images included in `srcset` attributes.
If you have the $content_width variable set (which is mandatory for themes in the .org Theme Directory), then this width overrides the max_srcset_image_width. Using @joemcgill’s example above to remove the default width wont work if you have $content_width set to a lower value.
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.
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?