Currently WebP versions are only generated for images to the Media Library. WebP versions are not generated for JPEG images that are added to site in other ways, Adding support for the wpadverts media uploader would be awesome
Hi,
i will look into integrating with one of the WebP plugins, it should be available in the next release, although i cannot tell right now which plugin i will be integrating with, proably the one with the most installs that does not rely on any third-party services.
BTW. I tested with Converter for Media plugin https://pl.ww.wp.xz.cn/plugins/webp-converter-for-media/ and it works fine on my dev site without any special changes, few notes though:
- The plugin does not seem to do conversion on-upload but rather somewhere in the background, so after uploading a file it might look like the file is a JPG file, but in the preview or when viewing the Ad it should be already converted to webp.
- The Converter for Media overwrites file paths, so in the source code the file will still have .jpg or .png extension, but if you investigate with Chrome Developer Tools for example you will see the file type is webp (i suppose it is doing this to avoid changing your posts and pages content).
These blog posts are almost 3 years old, it’s unclear when and if this will be merged.
Thanks for the feedback Greg, I dont think the Converter for Media plugin is suitable for me due to its limitations and also considering the fact that hosting plan has limited Nvme ssd storage. immediate conversion on upload is better
Hello Greg,
This code below seems to work for this plugin https://ww.wp.xz.cn/plugins/webp-uploads/
Kindly review
/**
* Generate Modern Image Formats for new WPAdverts gallery uploads
*/
function wpadverts_generate_modern_formats( $attachment_id, $post ) {
// Target only WPAdverts gallery uploads
if ( empty( $_REQUEST['adverts_gallery'] ) ) return;
// Ensure metadata exists - triggers Modern Image Formats automatically
if ( ! wp_attachment_is_image( $attachment_id ) ) return;
$metadata = wp_get_attachment_metadata( $attachment_id );
$file = get_attached_file( $attachment_id );
if ( ! $metadata && $file && file_exists( $file ) ) {
wp_generate_attachment_metadata( $attachment_id, $file );
}
}
add_action( 'wp_insert_attachment', 'wpadverts_generate_modern_formats', 20, 2 );
/**
* Enable fallback support (optional)
*/
function wpadverts_enable_modern_fallback() {
if ( current_user_can( 'manage_options' ) && ! get_option( 'webp_enable_fallback' ) ) {
update_option( 'webp_enable_fallback', true );
}
}
add_action( 'init', 'wpadverts_enable_modern_fallback' );
I haven’t looked at it, but if this code works for you put it in your theme functions.php file or create a new blank plugin (https://wpadverts.com/blog/how-to-use-code-snippets-in-wordpress/) and put it there, you do not need it in the WPAdverts core.