Add static fallback for animated images if user prefers reduced motion
-
Hi and thanks for the useful plugin!
How can we provide static fallback images to animated images uploaded by WordPress admins in case the client user prefers reduced motion?
Best practice seems to be: extend source set using media media=”(prefers-reduced-motion: reduce)” (Source: https://css-tricks.com/gifs-and-prefers-reduced-motion/ ). TinyPNG does not seem to handle this yet.
So ideally when uploading (or batch optimizing) images, each animated image should add an alternative static version that should be added to the source set.
Alternatively, we could work around a missing static alternative and hide the image altogether using CSS, provided that there was a class name indicating that a post thumbnail container has an animated image inside.
As a workaround of a workaround, I could use
add_filter( 'post_thumbnail_html'
and add such a CSS class name manually. To do it properly, I would have to open each image file stream and check each GIF, webp or avif for an animation signature. More pragmatically, I currently check for a.gif
string anywhere inside the thumbnail section which of only works because TinyPNG leaves animated GIFs untouched and does not make animated webp’s out of theme.Reading my workaround code, we can’t even be sure if the post_thumbnail_html filter will be applied before, after, or instead of what TinyPNG does.
Trying to sum up my confusion and end with 2 simple questions:
Is there a TinyPNG filter / hook that I should use instead of post_thumbnail_html ?
Did I miss a setting (or paid pro function) to make TinyPNG handle animated images properly (i.e. convert GIF to webp and add a static fallback for reduced motion preference)?
The page I need help with: [log in to see the link]
- The topic ‘Add static fallback for animated images if user prefers reduced motion’ is closed to new replies.