Replacing image with cropped version causes srcset references getting outdated
-
Scenario
- Created an Image Slider with Gutenslider.
- Each image in the slider gets its
srcsetmarkup. I assume it uses WP’s default “Responsive Image” mechanism. - Sometimes later I decided to crop the images in the series a bit further so that more of them gets readable.
- I cropped them on my computer with my image software.
- Media Library → List Image → Identify Image of my series → “Replace Image” (this action comes from your plugin) → Replaced it with the cropped image version on my computer. Did this for all 5 images in the slider.
❌ After that: All images showed as broken (only their ALT text)
- Reason: The
srcsetreferences were not updated and hence all point to files which don’t exist anymore! - Because in the new
srcsetof the corresponding image files the-XXXxYYYsuffix part changed due to the slightly different aspect ratios of the cropped images. (e.g. 1024×796 became 1024×838).
💡 Proposal: When the plugin replaces an image it also updates the
srcsetaccordingly in all existing markup. This should be easily possible without doubt, as in well-formed markup the mainsrcattribute of the image is the same unchanged URL and also in theclassattribute it has the unique media library identifierwp-image-1234.💡 If this is not possible then the minimal improvement would be to compare the old vs the new image dimensions and give a warning to the user that updating an image with an image of different proportions,
- may result in layout issues if not having used percentual/responsive image layout techniques (lesser problem)
- and will certainly result in srcset file references to break which will render various blocks to have broken images! You will need to re-create image markup (the very task which you wanted to spare yourself by using the plugin).
The topic ‘Replacing image with cropped version causes srcset references getting outdated’ is closed to new replies.