0

I'm using the following attachment image sizes in my theme: "thumbnail" (320) "medium" (640), "medium_large" (768) and "large" (1280).

The default WordPress "srcset" and "sizes" attributes on the tags are causing the browser to download unnecessarily large images in large viewports. For example, some of my layouts display the images in a grid with multiple columns, so it's not necessary to load the largest version of the image in these cases.

Is there a way for me to specify the maximum image size that should be downloaded?

Specifically, I tried looking for a way to customize the "srcset" attribute to exclude anything larger than 768px, but can't seem to figure out how to do this.

Any advice is really appreciated.

Ralph
  • 397
  • 1
  • 4
  • 16

1 Answers1

0

Try

apply_filters( 'max_srcset_image_width',int $max_width,array $size_array )

https://developer.wordpress.org/reference/hooks/max_srcset_image_width

More notes and hooks: https://make.wordpress.org/core/2015/11/10/responsive-images-in-wordpress-4-4/

pixleight
  • 188
  • 7
  • Thanks for the tip. I'll try to this. Do you know if there a way to do this for images on specific pages only? Rather than having it apply across the board. I guess I could do an apply_filters() followed by a remove_filter() call for each image, but is this a good practice performance-wise? Thanks again. – Ralph Aug 20 '17 at 16:00