Created
July 7, 2018 05:54
-
-
Save Dartui/6a920904995f5f340fc14322d81f3721 to your computer and use it in GitHub Desktop.
Encrypts scripts and styles version from URL in WordPress
This file contains 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
<?php | |
add_filter('script_loader_src', 'encrypt_assets_version'); | |
add_filter('style_loader_src', 'encrypt_assets_version'); | |
function encrypt_assets_version($src) { | |
return preg_replace_callback('/(\?ver=)(\d+?(?:\.\d+)?(?:\.\d+)?)\b/', function ($matches) { | |
return sprintf('%s%s', $matches[1], substr(md5($matches[2]), 0, 6)); | |
}, $src); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment