How to use and convert WebP images in WordPress
The biggest question for most people who build websites with WordPress is how to use and convert WebP images in WordPress.
One of the factors that can affect your site’s performance is the images on it. If they aren’t optimized, they can slow down your page’s loading, which makes the site sluggish and causes lost sales and conversions.
So, making your site fast, well structured, and responsive on phones will give you more visibility in search engines and, as a result, more conversions.
One way to make your image format lighter is to use the WebP image format.
In this article, you’ll learn about WebP and how to use this format on your WordPress site.
Contents
How to use and convert images to WebP in WordPress
Prerequisites
To start, your domain and website need to be hosted with a web hosting provider, or you may already have hosting on MigraCloud’s infrastructure.
- Have WordPress installed
- Access to the WordPress admin dashboard
What Exactly Is WebP
Having a website that loads quickly is probably every webmaster’s biggest dream. One of the ways to optimize page speed is by using WebP image formats. But what is WebP, after all?
WebP is a file format developed by Google back in 2010. It offers a higher compression rate for images while keeping their quality intact. Webmasters and developers can create images with smaller file sizes, so you can load them faster. This format uses more powerful compression methods, both lossy and lossless, compared to the PNG and JPEG formats.
How to use and convert images to WebP in WordPress
You can display WebP images in WordPress using the WebP Express plugin.
The WebP Express plugin uses the WebP Convert Library to modify images. This plugin works as a converter that generates WebP for browsers that support this format, but displays JPG or PNG for browsers that don’t.
Installing the plugin is quite simple: in the WordPress admin dashboard, go to “plugins” and “add new”.
In the search box, type “WebP Express” and you’ll find the WebP Express plugin, with the “Install now” option.
After clicking the install option, just select the activate option that appears right after the process.
After activation, it should appear like this in your installation:
After that, go to the sidebar and click Settings, then WebP Express, as shown in the figure below:
Now let’s configure it:
In the first block, where it says “Operation mode:”, leave the option “Varied image responses” selected.
In the “Varied image responses” mode, WebP Express creates redirect rules for images, so that a request for a JPEG will result in a WebP, but only if the request comes from a WebP-enabled browser. If a WebP already exists, it is served immediately. Otherwise, it is converted and then added.
Next, under GENERAL, set the options as shown in the image below:
- Scope: uploads and themes
- Image types to work with: JPEGs and PNGs
- Destination folder: in a separate folder
- Destination structure: Document Root
- Cache-Control header (set it to Custom and paste the code): public, max-age:86400, stale-while-revalidate=604800, stale-if-error=604800
Under .htaccess rules for webp generation, select the options “Enable direct redirection to existing converted images?” and “Enable redirection to converter?” as shown in the image below:
In the Conversion block, under Jpeg options:
- WebP encoding: Automatic
- Lossy quality: Fixed quality > 70
- Lossless quality: Apply “Near-lossless” quality pre-processing: 65
Under PNG options:
- WebP encoding: Automatic
- Lossy quality: 75 Alpha quality: 75
- Lossless quality: Apply “Near-lossless” quality pre-processing: 65
Metadata: Copy all metadata to WebP
Under Conversion method, enable the GD Extension option.
Select the “Convert on upload” option.
The “Bulk convert” option will be covered later on, so for now you don’t need to do anything with it.
Enable the Alter HTML option.
Turning this on changes the HTML code, so that WebP images are served to WebP-compatible browsers. It is recommended to enable this even when redirection is also enabled, so that the varied image responses are only used for images that can’t be replaced in HTML. Varied responses usually lead to lower caching in proxies and CDNs. And if users download these images, they will get a jpg / png extension, even though they are WebP.
- Replace image URLs: Choose this option
- Only do the replacements in WebP-enabled browsers: Check this option
- Under How to replace, check the option: The complete page (using output buffering)
Done! Now go to “Save settings” and save your configuration. To finish our setup, go back to the Bulk Convert option and click Bulk Convert.
The plugin will now convert all of your images. It’s worth doing this outside business hours.
Conclusion
When you decide to use WebP images in WordPress, it’s without a doubt one of the best decisions you’ll make for your site’s performance.