Skip to content

Instantly share code, notes, and snippets.

@Korveld
Created June 7, 2023 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Korveld/0dc77f7e142d45f7177c9062024f461c to your computer and use it in GitHub Desktop.
Save Korveld/0dc77f7e142d45f7177c9062024f461c to your computer and use it in GitHub Desktop.
PHP detect WebP image support
<?php if (strpos( $_SERVER['HTTP_ACCEPT'], 'image/webp' ) !== false) { ?>
<section
class="section"
style="background-image:url(path-to-webp-image);"
>
<?php } else { ?>
<section
class="section"
style="background-image:url(path-to-fallback-image);"
>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment