[wp-trac] [WordPress Trac] #40469: How to remove full size image path from srcset and more intelligent choices in srcset candidate list
WordPress Trac
noreply at wordpress.org
Sun Apr 16 22:41:17 UTC 2017
#40469: How to remove full size image path from srcset and more intelligent choices
in srcset candidate list
-----------------------------+-----------------------------
Reporter: lisota | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Post Thumbnails | Version: 4.7.3
Severity: normal | Keywords:
Focuses: |
-----------------------------+-----------------------------
On our site, we have a number of image sizes registered in WP, in addition
to the default ones, for a variety of purposes. A large one to fill the
width of our column, smaller ones for some custom image output, etc.
The result of this is a sloppy srcset candidate list filled with URLs that
may make no logical sense in a particular location in the markup. WP does
have an upper size limit to prevent giant images from being in srcset, and
also matches aspect ratio, but nothing else.
I have been able to hack together a filter using
`wp_calculate_image_srcset_meta` to unset various sizes in the `sizes`
array. But if the full size of the image is smaller than the
`max_srcset_width` parameter, it still gets included, and there should be
some way to remove it. The full size of the image is not part of the
`sizes` array in image_meta.
It actually points to a larger issue with WP srcset implementation, which
is that is mindlessly fills the HTML with srcset candidates that in many
instances would never be used, adding lots of excess markup that a
developer wouldn't add.
For example, we have a 300px wide sidebar where we output an image. The
sidebar is never larger than 300px, and even is that size in our
responsive site on mobile. The srcset outputs a 150px, 200px, 300px,
600px, 768px and 1240px, based on the sizes registered in our installation
and the built-in ones. Logisitically, all that is really needed for this
layout is 300px and probably the 600px version. We have all sorts of
examples like this where the srcset includes either smaller or larger
sizes than are physically possible in a given layout.
Obviously WordPress cannot know how a site is styled, but it feels like
there needs to be a more robust way of dealing with this. It is not a
great feature to load up on unneeded markup.
As a theme developer, I would like the ability to constrain the srcset
candidate list in an intelligent way each time I output img tags into the
markup. It is easy for me to say "at this location, this image will never
be smaller than 300px, so don't give me anything smaller, and will also
never be bigger than 300px, so only go up to a 2x version and skip
anything larger.
I'm guessing this is exacerbated by a variety of themes and pluging that
may load up on extra registered image sizes as well.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40469>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list