functions – Convert Image to Webp on upload without plugin


I try way to convert image on upload automatically.

I try a lot of plugins but all of that work over .htaccess and make duplicate image in upload folder example. imagename.png.webp

I want convert image on upload to webp.

Is there a code for the function.php? Example now I have code for randomize image name on upload you can see that in below.

Is there code similar for convert image to webp immediately after upload. Thx

// randomize upload filenames function htg_randomize_uploaded_filename( $filename ) {

// does it have an extension? grab it
$ext = empty( pathinfo( $filename )[‘extension’] ) ? ” : ‘.’ . pathinfo( $filename )[‘extension’];

// return the first 8 characters of the MD5 hash of the name, along with the extension
return substr(md5($filename), 0, 8) . $ext;

add_filter( ‘sanitize_file_name’, ‘htg_randomize_uploaded_filename’, 10 );

kuribo 2 months 2023-04-06T22:24:22-05:00 0 Answers 0 views 0

Leave an answer