[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
Fri Dec 18 13:41:09 UTC 2015


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

Comment (by joemcgill):

 Hi again,

 For situations like these, there is
 [https://developer.wordpress.org/reference/hooks/wp_calculate_image_sizes/
 a filter included] in `wp_calculate_image_sizes()` that passes the image
 dimensions, `src` URL, attachment metadata, and attachment id. These can
 be used to change the `sizes` attribute based on the layout size of your
 image at different breakpoints.

 It's hard to tell without more information whether this filter would be
 sufficient for your use case. From your comment above, it sounds like your
 writing the HTML for your grid directly inside the post editor, which may
 complicate things a bit, but I believe it should work. You can see a
 couple of usage examples for the `wp_calculate_image_sizes` filter on
 [https://github.com/ResponsiveImagesCG/wp-tevko-responsive-images#hook-
 wp_calculate_image_sizes this GitHub page].

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


More information about the wp-trac mailing list