Disable the creation of srcset on SVGs #38
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
In #23 we changed some behavior on how the height and width of SVGs are set. Previously those values were set to
false
, which in some instances just gets translated to zero. But this caused some issues in a few places, like the block editor, as technically those values are supposed to be integers and if those aren't converted to integers, it will cause PHP errors. We fixed this by using the actual height and width of the SVG and if those don't exist, we default to 100.We've had a few reports though of where SVGs are now showing up larger than expected. I've only been able to reproduce this issue if directly using
wp_get_attachment_image
to output an SVG, though curiously I'm getting the wrong size images on the previous release as well. It seems the bug with the new release has to do with addingsrcset
to these images, whereas previously those weren't being added as we were overriding height and width to befalse
. I don't think we needsrcset
, so this PR removes that from all SVGs.On the previous release, if using
wp_get_attachment_image
and not setting a size (so defaulting to thumbnail) I get this markup:This is incorrect as I should be getting an image that is 150x150, so I get a larger than expected image.
Using the same settings on the newest release:
This gives me the right height and width set but because of the
srcset
, I can potentially get a larger or smaller image on various breakpoints.After the changes in this PR:
Right height and width but no more
srcset
orsizes
.Checklist:
Changelog Entry