Skip to content

Instantly share code, notes, and snippets.

@topleague
Created December 16, 2017 05:12
Show Gist options
  • Save topleague/1bf42403e5309db54fa275380844c53a to your computer and use it in GitHub Desktop.
Save topleague/1bf42403e5309db54fa275380844c53a to your computer and use it in GitHub Desktop.
Convert PNG/JPG Files into WebP Format in WordPress
#Apache WebP Configuration
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{DOCUMENT_ROOT}/$1.webp -f
RewriteRule ^(wp-content/uploads.+)\.(jpe?g|png)$ $1.webp [T=image/webp,E=accept:1]
</IfModule>
<IfModule mod_headers.c>
Header append Vary Accept env=REDIRECT_accept
</IfModule>
AddType image/webp .webp
@sean-varnham
Copy link

#Hi topleague, is this meant to actually convert the files from jpg and png to webp format? It looks like this code won't do anything to the file other than telling the server to accept the extension. To properly convert an image to webP you need to change the way the images are coded. Have you got an examples of how to change the encoding to webP from jpe?g/png with #JS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment