[wp-trac] [WordPress Trac] #46885: Improvements/Issues with srcsets, additions to wp_calculate_image_srcset

WordPress Trac noreply at wordpress.org
Fri Apr 12 15:02:53 UTC 2019


#46885: Improvements/Issues with srcsets, additions to wp_calculate_image_srcset
-------------------------+------------------------------
 Reporter:  pinktank     |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Media        |     Version:  5.1
 Severity:  normal       |  Resolution:
 Keywords:               |     Focuses:
-------------------------+------------------------------

Comment (by joemcgill):

 Hi @pinktank,

 Welcome to Trac and thanks for sharing your ideas of what you'd like to
 see improved!

 Let me try to respond to each of these requests separately.

 **1. Include a way to not include the original src in srcset.**

 This could currently be accomplished by adding a filter to the
 `wp_calculate_image_srcset` hook, which is
 [https://developer.wordpress.org/reference/functions/wp_calculate_image_srcset/
 documented here]. That filter has access to the `src` URL, so you could
 loop through the source list and unset the orginal source from the list at
 that point, before the `srcset` attribute is created.

 **2. There is something strange with the way the srcset is ordered.**

 This is actually intentional behavior. Browsers do not pay any attention
 to the order of sources in a `srcset` list. However, when this feature was
 shipped, we chose to list the original `src` first in order to work around
 a bug in iOS 8 which caused the first source to always be selected. See:
 https://core.trac.wordpress.org/ticket/35030.

 **3. Accept an array of named image sizes to create custom srcsets**

 To limit the sources available in a srcset attribute, this could also be
 accomplished via the `wp_calculate_image_srcset`, by passing the source
 list through some kind of white list, though I would recommend against
 this, as it's advantageous to include as many options for browsers as is
 reasonable. However, if the goal here is to reduce the number of files
 that are created when an image is uploaded, that is something that happens
 separately from the `srcset` generation and is something we would want to
 handle with more use cases in mind.

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


More information about the wp-trac mailing list