Site icon Hip-Hop Website Design and Development

Change extension to .jpg when webp is not supported

I’m trying to show jpg in browsers that don’t support webp without using a plugin,

When uploading images, I upload both as webp and jpg.

İ add webp by default, I need to change the extension to .jpg when entered from a browser that does not support webp, i found a php code about it but my attempts were unsuccessful.

<?php
if (strpos( $_SERVER['HTTP_ACCEPT'], 'image/webp' ) !== false) {
  //do nothing when webp is supported
} else {
  //.webp replace .jpg
}
?>