rosell-dk / webp-express

Wordpress plugin for serving autogenerated WebP images instead of jpeg/png to browsers that supports WebP
GNU General Public License v3.0
221 stars 63 forks source link

Programmatically get the webp version of images #559

Open yesh opened 2 years ago

yesh commented 2 years ago

Cheers @rosell-dk for your work!

I was wondering if there's a way to programmatically get the webp images generated by your plugin in the code.

for example, I'm using this snippet to get and control sizes of my images in various components throughout my application:

<picture>
  <source
    srcset="{{ wp_get_attachment_image_srcset(@$id) }}"
    sizes="{{ $sizes }}"
  />
  <img src="{{ $src }}" alt="image">
</picture>

and I was wondering if there's a way to get the webp images generated by the plugin with a function like this way:

<picture>
  <source
    srcset="{{ wp_get_webpexpress_images(@$id) }}"
    sizes="{{ $sizes }}"
    type="image/webp"
  />
  <source
    srcset="{{ wp_get_attachment_image_srcset(@$id) }}"
    sizes="{{ $sizes }}"
  />
  <img src="{{ $src }}" alt="image">
</picture>

thank you for your help