Skip to content

Instantly share code, notes, and snippets.

@westonruter
Created September 14, 2017 18: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 westonruter/3b845e58b72031b8f59f3fde4b79d4b4 to your computer and use it in GitHub Desktop.
Save westonruter/3b845e58b72031b8f59f3fde4b79d4b4 to your computer and use it in GitHub Desktop.
One approach to getting all scripts and styles cache-busted
<?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