[wp-trac] [WordPress Trac] #35128: Srcset may include a much-too-large image, apparently no way to set size in context

WordPress Trac noreply at wordpress.org
Sat May 28 14:42:12 UTC 2016

#35128: Srcset may include a much-too-large image, apparently no way to set size in
 Reporter:  programmin    |       Owner:  joemcgill
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  Media         |     Version:  4.4
 Severity:  normal        |  Resolution:  worksforme
 Keywords:                |     Focuses:
Changes (by joemcgill):

 * status:  reviewing => closed
 * resolution:   => worksforme
 * milestone:  Awaiting Review =>


 Hi @programmin,

 Apologies on the delay in responding to your ticket. You're correct that
 the best way for theme authors to adjust for use cases where an available
 image size is slightly smaller that what the browser needs, is to modify
 the sizes of images WordPress creates on upload and/or add additional
 sizes using `add_image_size()` which fit the needs of your theme. Since
 `srcset` and `sizes` are evaluated by browsers, and we have no way of
 impacting the way browsers choose to implement their source selection
 process, this is probably the best we can do.

 If you need to use the `wp_calculate_image_sizes` filter differently on
 particular layouts, I would consider either adding the filter from within
 your custom template, or being creative with which conditional tags you
 check before applying the filter. For example, if you only want to apply
 the filter on the front page of the site, you could do something like:

 // Only add the filter on the front page of the site.
 if ( is_front_page() ) {
   add_filter( 'wp_calculate_image_sizes', 'my_homepage_srcset_filter', 10,
 2 );

 function my_homepage_srcset_filter( $sizes, $size ) {
   // Add function logic here.

 Since WordPress doesn't know anything about your intended markup when this
 function is called, it's best if this kind of filtering/customization is
 handled by theme authors. We also have to be careful about creating a
 bunch of new image sizes out of the box due to the fact that many
 WordPress users are on shared hosting with limited resources. I'm going to
 go ahead and close this as a ''worksforme'' for now, but feel free to
 continue the conversation or reopen if you have a use case that you don't
 believe can be resolved using the current set of tools available and we
 can reevaluate. Thanks again.

Ticket URL: <https://core.trac.wordpress.org/ticket/35128#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list