Created
September 14, 2017 18:54
-
-
Save westonruter/3b845e58b72031b8f59f3fde4b79d4b4 to your computer and use it in GitHub Desktop.
One approach to getting all scripts and styles cache-busted
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 | |
define( 'ASSET_CACHE_INCREMENTOR', 'cachekey-' . time() ); // Source this from anywhere. | |
add_action( 'wp_enqueue_scripts', function() { | |
$assets = array_merge( | |
wp_scripts()->registered, | |
wp_styles()->registered | |
); | |
$core_version = get_bloginfo( 'version' ); | |
foreach ( $assets as $asset ) { | |
if ( empty( $asset->ver ) ) { | |
$asset->ver = $core_version; | |
} | |
$asset->ver .= '-' . ASSET_CACHE_INCREMENTOR; | |
} | |
}, 1000 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment