Discover in this tutorial how to modify the quality of WebP images when uploading them to WordPress with a simple code snippet.
WordPress 5.8 introduces quite a few new features, including support for WebP format images, a more modern and efficient image format.
By default, WordPress compresses the images you upload to the media library to 82% quality.
In a previous tutorial I explained how you can modify the quality of JPG images and today we are going to see how to control this parameter in WebP images using the WordPress filter wp_editor_set_quality
.
Let’s get to it.
Snippet to control the quality of the WebP images you upload to WordPress
If you want WebP images not to lose quality when uploaded to WordPress, add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
It’s that simple.
Using the wp_editor_set_quality
filter you indicate that when the file type ($mime_type
) is WebP you set the quality you want WordPress to apply when uploading your images.
In this case you set it to 100 so that it respects the quality of the original image.
Of course, you can also play with other values, as long as they are between 0 and 100. Although I recommend, as a general rule, to stay between 70-100% quality.
Conclusion
Now you know how to control the quality at which WebP images will be uploaded to the WordPress media library.
Any questions? Let me know in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉