Skip to content

Instantly share code, notes, and snippets.

@JustinSainton
Forked from danielbachhuber/gist:6719651
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save JustinSainton/d6afe106e792c225a437 to your computer and use it in GitHub Desktop.

Select an option

Save JustinSainton/d6afe106e792c225a437 to your computer and use it in GitHub Desktop.
<?php
/** Automatically append mtime to script and style versions for cache-busting action **/
add_action( 'wp_enqueue_scripts', function() {
global $wp_styles, $wp_scripts;
foreach( array( 'wp_styles', 'wp_scripts' ) as $resource ) {
foreach( $$resource->registered as $name => $registered_resource ) {
// Not hosted here
if ( false === stripos( $registered_resource->src, home_url() ) )
continue;
$file = str_replace( 'wordpress/', '', str_replace( home_url( '/' ), ABSPATH, $registered_resource->src ) );
$mtime = filectime( $file );
$$resource->registered[$name]->ver = $$resource->registered[$name]->ver . '-' . $mtime;
}
}
}, 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment