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 );

  • Anybody ansver ?
    – kuribo
    Apr 7 at 20:12


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.