Skip to content

Instantly share code, notes, and snippets.

@hearvox
Created May 29, 2017 14:44
Show Gist options
  • Save hearvox/98ed23dd3be1ef3cd44f87a4139c14a2 to your computer and use it in GitHub Desktop.
Save hearvox/98ed23dd3be1ef3cd44f87a4139c14a2 to your computer and use it in GitHub Desktop.
Use filemod timestamp for version number for WordPress script registration, to bust cache.
<?php
/**
* Use filemod timestamp for version number.
*
* For setting cache-busting version number in script registrations. Usage:
* wp_register_script( 'handle', $file_url, array(), headecon_filemod_vers( $file_path ) );
*
* @param string $path Path of script/style file
* @return string $vers File-modification timestamp or WordPress version
*/
function headecon_filemod_vers( $path ) {
$vers = '';
if ( file_exists( $path ) ) {
$vers = filemtime( $path );
} else {
$vers = get_bloginfo('version');
}
return $vers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment