WordPress Snippets at WPcustoms

Use last modified time for script enqueue version

If you change your js and css file it makes sense to use a version number so browsers know when a cache refresh is required. The filemtime function is a perfect solution for this.
We set our css\js file as a variable and getting the last modified time for $ver part of wp_enqueue_style


/**
 * Snippet Name: Use last modified time for script enqueue version
 * Snippet URL: http://www.wpcustoms.net/snippets/use-last-modified-time-for-script-enqueue-version/
 */
 // reference: wp_enqueue_style( $handle, $src, $deps, $ver, $media );
function add_styles()
{
     $css_file = get_stylesheet_directory() . '/css/style.css';
     wp_enqueue_style( 'css-file', get_stylesheet_directory_uri().'/css/style.css', NULL, filemtime($css_file) );
}
add_action( 'wp_enqueue_scripts', 'add_styles' );