Created
December 16, 2017 05:12
-
-
Save topleague/1bf42403e5309db54fa275380844c53a to your computer and use it in GitHub Desktop.
Convert PNG/JPG Files into WebP Format in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#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?