Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Save resized images as WebP

The smaller copies WordPress makes of your JPEG and PNG uploads are saved as WebP, which is usually 25–35% smaller. The original upload stays as it is.

  • Type PHP
  • Runs Everywhere (runs as WordPress loads)
  • Category Media
  • Tested with WordPress 7.1
PHP
<?php

add_filter(
	'image_editor_output_format',
	static function ( $formats ) {
		// Only when the server can actually write WebP.
		if ( wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {
			$formats['image/jpeg'] = 'image/webp';
			$formats['image/png']  = 'image/webp';
		}
		return $formats;
	}
);

Good to know

Every current browser shows WebP. Only new uploads are affected.

In these packs

  • Images and media: Sharper, lighter images, tidier uploads and a more useful media library.
  • More speed: More ways to load less: block styles, speculative loading, fewer scripts.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.