We'll create fresh WordPress site with Squidge installed. You have 20 minutes to test the plugin after that site we'll be deleted.
Squidge is a FREE WordpPress Plugin built for developers in mind compressing and convert images using jpegoptim,
optipng, cwebp, and libavif. It’s extremley simple to use and is designed to increase PSI and boost rankings.
Image compression in WordPress can be costly, confusing and sometimes just simply don’t work. We have aimed to simplify
the process by requiring the developer to install the required package on the operating system and Squidge does the
hard work for you.
cwebp
and libavif
libraries.Squidge compresses and converts image files when the user has uploaded a file to WordPress.
jpegoptim
.optipng
..webp
files using cwebp
with the appended extension e.g. image.jpg.webp
..avif
files using libavif
with the appended extension e.g. image.jpg.avif
.To render images in templates, you can either set up nginx or apache rules to serve images dynamically or used the
squidge_image helper function. This dynamically checks if an .avif
or .webp
file is available on the file system
and returns the output.
/**
* Returns a <picture> element with source media for the standard file passed
* (such as a JPG), the .avif file, the .webp file (if to exist on the file system).
*
* Appropriate <source> elements for image sizes with max widths.
* Finally, the main be outputted with alt and title text.
*
* - If lazy is true, the data-src or data-srcset will be appended.
* - If a class is set, the class will be outputted on the <picture> element.
*
* @param $image_id
* @param string $class
* @param false $lazy
* @return string
*/
function squidge_image($image_id, $class = '', $lazy = false)
<picture class="picture">
<!-- Loads if AVIF is supported and the window is smaller than 400px wide -->
<source media="(max-width: 400px)" srcset="/sample-image.jpg.avif" type="image/avif">
<source media="(max-width: 400px)" srcset="/sample-image.jpg.webp" type="image/webp">
<source media="(max-width: 400px)" srcset="/sample-image.jpg">
<!-- AVIF & Wep Initial Sizes -->
<source srcset="/sample-image.jpg.avif" type="image/avif">
<source srcset="/sample-image.jpg.webp" type="image/webp">
<!-- Default -->
<img src="/sample-image.jpg" alt="Alt text" title="Sample JPG">
</picture>
Written by Ainsley Clark