Some filters would help
-
Hello Meow –
Your plugin was recommended to me by another WP dev. I’ve been looking for a Guttenberg galley that is smart about how it uses the img tag’s srcset and sizes attributes. Specifically, the one that’s plugins consistently get wrong is the setting for sizes. That said, your plugin is better than the others I’ve looked at ??
<sidebar>
This article does a great job slogging through the details:
https://ericportis.com/posts/2014/srcset-sizes/
TL;DR – The magic comes from the sizes setting, not srcset. Without a good sizes= value, the browser is going to make bad decisions about which image to pick from the srcset.
<sidebar>
I’ve been looking at your code, looking for an appropriate filter but thus far I can’t find anything. Off the top of my head (read: I’m been looking about 30 mins and in that time can not master your code), it looks like class Meow_Gallery_Generator > method build_next_cell is where a filter would be ideal That is, being able to modify the args that are sent to wp_get_attachment_image.
Ultimately, I need to be able to do two things:
1) Have a clear understanding of what image(s) is going to be modify. The problem with using the filters in core’s wp_get_attachment_image is you don’t get any context. That is, it doesn’t tell what image location is being rendered. Is it a gallery image? Or some other image?
2) Use the $content_width in doing the calculation for the sizes value/string.
In other words, the more args / attributes you can pass in the filter the better we’ll be able to properly modify the args for wp_get_attachment_image. Things such as: galley type, columns, the blocks’s custom CSS class, etc.
For example, this is an image from Meow Galley: Square:
<img width="1023" height="539" src="https://gg2.dev.cc/wp-content/uploads/2019/10/Princeton-University-Rowing-Crew-2048x1079.jpg" class="wp-image-625" alt="" srcset="https://gg2.dev.cc/wp-content/uploads/2019/10/Princeton-University-Rowing-Crew.jpg 2048w, https://gg2.dev.cc/wp-content/uploads/2019/10/Princeton-University-Rowing-Crew-300x158.jpg 300w, https://gg2.dev.cc/wp-content/uploads/2019/10/Princeton-University-Rowing-Crew-768x405.jpg 768w, https://gg2.dev.cc/wp-content/uploads/2019/10/Princeton-University-Rowing-Crew-576x303.jpg 576w, https://gg2.dev.cc/wp-content/uploads/2019/10/Princeton-University-Rowing-Crew-992x523.jpg 992w, https://gg2.dev.cc/wp-content/uploads/2019/10/Princeton-University-Rowing-Crew-1200x632.jpg 1200w, https://gg2.dev.cc/wp-content/uploads/2019/10/Princeton-University-Rowing-Crew-1500x790.jpg 1500w"<strong> sizes="33vw"</strong> />
It’s a three-column gallery. Sizes=”33vw” is good, but it could be better. That value is telling the browser this image is going to be 33% of the total view width. That’s not quite correct. It’s really 33% of the $content_width – which is a significant different – , and then at some lower breakpoint – depending on the theme – 100vw. That is, on a small screen the image CSS might be width 100%.
Finally, since this might help, he’s a plugin a did for the regular Gutenberg image block:
https://gitlab.com/WPezPlugins/wpez-guten-better-image
Since I used the block’s settings (e.g., width), as well as the $content_width I’m also to craft a more precise sizes= value.
- The topic ‘Some filters would help’ is closed to new replies.