rosell-dk / webp-express

Wordpress plugin for serving autogenerated WebP images instead of jpeg/png to browsers that supports WebP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Programmatically get the webp version of images

yesh opened this issue · comments

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