[wp-trac] [WordPress Trac] #34678: Responsive Images: Check if content images already have a sizes attribute
WordPress Trac
noreply at wordpress.org
Sun Nov 22 11:52:17 UTC 2015
#34678: Responsive Images: Check if content images already have a sizes attribute
----------------------------+------------------------
Reporter: jaspermdegroot | Owner: joemcgill
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: 4.4
Component: Media | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
----------------------------+------------------------
Comment (by jaspermdegroot):
@azaozz
First of all, I wouldn't recommend inserting the `sizes` attribute in the
image markup in the post editor, but there might be situations where it is
the best (least worst) solution. The limitation of the filter is that you
don't know anything about the context. So if a specific layout is used
somewhere which warrants a custom `sizes` value, you can only use the
filter if the combination of image ID/URL and size is unique for that
situation.
Having a `sizes` attribute without a `srcset` attribute is indeed useless.
That would be bad HTML, but not broken/invalid as far as I understood from
the specs. Only a `srcset` attribute with `w` descriptors and no `sizes`
attribute is invalid. However, when users add a custom `sizes` attribute
they know of course that their final markup will also contain the `srcset`
and I suppose what matters is if the final markup is good or not.
> Alternatively we can check for the presence of sizes and srcset, and if
either is present can skip generating both for that image.
That would be better than not checking at all, to prevent two `sizes`
attributes in the final markup. Otherwise we would have to document
somewhere that you are not allowed to add that attribute.
This would make it more difficult though to add a simple custom `sizes`
attribute since you would also have to manually create the `srcset`
attribute. So I think we should decide if there are good use cases for
inserting a custom `sizes` attribute in the image markup instead of using
the filter, and if so, I suggest we don't make that harder by requiring a
`srcset` as well.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34678#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list