Skip to content

Instantly share code, notes, and snippets.

@adamsilverstein
Last active June 5, 2024 15:49
Show Gist options
  • Save adamsilverstein/35e9d9fcdb1933e67ce38a7ccb119f3d to your computer and use it in GitHub Desktop.
Save adamsilverstein/35e9d9fcdb1933e67ce38a7ccb119f3d to your computer and use it in GitHub Desktop.
Output WebP images from PNG uploads
<?php
/**
* Outout WebP sub size images from PNG uploads.
*
* @wordpress-plugin
* Plugin Name: WebP-from-PNG.
* Description: Output WebP sub size images for PNG uploads.
* Plugin URI:
* Version: 1.0.0
* Author: Adam Silverstein, Google
* License: Apache License 2.0
* License URI: https://www.apache.org/licenses/LICENSE-2.0
*/
function filter_image_editor_output_format( $mappings ){
$mappings[ 'image/png' ] = 'image/webp';
return $mappings;
}
add_filter( 'image_editor_output_format', 'filter_image_editor_output_format' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment