Skip to content

Instantly share code, notes, and snippets.

@Dartui
Created July 7, 2018 05:54
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 Dartui/6a920904995f5f340fc14322d81f3721 to your computer and use it in GitHub Desktop.
Save Dartui/6a920904995f5f340fc14322d81f3721 to your computer and use it in GitHub Desktop.
Encrypts scripts and styles version from URL in WordPress
<?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