apply_filters( 'max_srcset_image_width', int $max_width , array $size_array )
Filters the maximum image width to be included in a ‘srcset’ attribute.
Description Description
Parameters Parameters
- $max_width
-
(int) The maximum image width to be included in the 'srcset'. Default '2048'.
- $size_array
-
(array) Array of width and height values in pixels (in that order).
Source Source
File: wp-includes/media.php
Changelog Changelog
Version | Description |
---|---|
4.4.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
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?