Skip to content

Instantly share code, notes, and snippets.

@adamsilverstein
Last active August 25, 2022 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamsilverstein/262ec44a5cebe7ff8601b1e73301d07f to your computer and use it in GitHub Desktop.
Save adamsilverstein/262ec44a5cebe7ff8601b1e73301d07f to your computer and use it in GitHub Desktop.
Test setting WebP quality
<?php
/**
* Use the `wp_editor_set_quality` filter for testing.
*/
function set_webp_quality( $quality, $mime_type ) {
error_log( sprintf( 'wp_editor_set_quality mime type: %s', $mime_type ) );
if ( 'image/webp' === $mime_type ) {
return 1;
}
return $quality;
}
add_filter( 'wp_editor_set_quality', 'set_webp_quality', 10, 2 );
/**
* Specify WebP file output.
*/
add_filter( 'image_editor_output_format', function() {
return array(
'image/jpeg' => 'image/webp',
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment