WebP without a plugin
Use WordPress’s image_editor_output_format filter to save thumbnails as WebP, what it leaves as JPEG, and when a plugin is simpler.
Since WordPress 5.8 you can make WordPress save the image sizes it generates as WebP with a few lines of code. It is a good option if you like to keep plugins to a minimum — but it does not do quite what most people expect, so it is worth knowing the limits.
The snippet
Add this to a small must-use plugin (a PHP file in wp-content/mu-plugins) or a code snippets plugin, rather than a theme’s functions.php that a theme update can overwrite:
// Save new image sizes as WebP (WordPress 5.8+).
add_filter( 'image_editor_output_format', function ( $formats ) {
$formats['image/jpeg'] = 'image/webp';
$formats['image/png'] = 'image/webp';
return $formats;
} );
// Optional: WebP quality for those sizes (WordPress's default is 82).
add_filter( 'wp_editor_set_quality', function ( $quality, $mime_type ) {
return 'image/webp' === $mime_type ? 80 : $quality;
}, 10, 2 );
Your server’s GD or Imagick must support WebP — here is how to check.
What it changes
- Thumbnails and other generated sizes of new JPEG and PNG uploads are written as
.webpfiles. - Images inserted in posts at those sizes (Large, Medium, and the sizes in
srcset) are served as WebP.
What it does not change
- The file you uploaded stays on disk as a JPEG or PNG at full size. WordPress only applies the mapping when it writes new image files, so the original upload — and anything that links to it, such as a Full Size image or a lightbox — is still a JPEG.
- Existing images are untouched until their sizes are regenerated.
- There is no maximum size: a 4000-pixel phone photo is still stored at 4000 pixels (apart from WordPress’s own 2560-pixel
-scaledcopy). - Some plugins, older themes and email tools expect a
.jpgthumbnail name and may break when it ends in.webp. Test before you rely on it.
WordPress core once planned to switch this on for everyone in version 6.1, and the change was withdrawn before release, partly because of the storage and compatibility questions above. The WordPress performance team’s Modern Image Formats plugin builds on the same idea with more options.
When a plugin is simpler
If you want the uploaded file itself to become WebP, with a size limit and no leftover JPEG, WebP Auto Convert converts the upload before WordPress makes its sizes, so the original and every size are WebP and the file is scaled down to your Max width and Max height. Use one approach or the other, not both.
Frequently asked questions
Why is my full-size image still a JPEG after adding the filter?
Because the filter only affects files WordPress generates. The uploaded original is never re-encoded, so the full-size file keeps its original format.
Does the filter convert my existing Media Library?
No. It applies when sizes are created. Regenerating thumbnails with a tool such as WP-CLI’s media regenerate command creates WebP sizes for old images, but the originals stay JPEG.
Can I output AVIF instead?
Yes, on WordPress 6.5 or later with an image library that supports AVIF: map to image/avif instead of image/webp. Check Site Health → Info → Media Handling for AVIF support first.
Did this answer the question? No — open a support request