short-pixel-optimizer / shortpixel-image-optimiser

ShortPixel Image Optimizer WordPress Plugin
15 stars 7 forks source link

Enable webp/avif support for images outputed with wp_get_attachment_image #138

Open matthewgrzegorczyk opened 3 months ago

matthewgrzegorczyk commented 3 months ago

Shorptixel version: 5.6.2

I am trying to use webp/avif compression on the page, but as the site is custom build app on roots/bedrock I had to fix several things as the option of delivering next gen image formats via picture tag using wordpres hook didn't work out of the box.

image

I've notice that in the FrontController the replacement of <img> tag with <picture> tag happens only for the_content, the_excerpt and post_thumbnail_html. Is it possible that we add in here: https://github.com/short-pixel-optimizer/shortpixel-image-optimiser/blob/master/class/Controller/FrontController.php#L46 another option to run convertImgToPictureAddWebp? add_filter('wp_get_attachment_image', array($this, 'convertImgToPictureAddWebp'), 10, 4);

If not, maybe it's possible to add do_action hook which would enable advanded users to register it on their own? do_action('shortpixel/init_webp_hooks', $this, $webp_option)

matthewgrzegorczyk commented 2 months ago

@pdobrescu Did you had a chance to check the issue I am describing above?