Skip to content

Instantly share code, notes, and snippets.

@robneu
Last active December 17, 2018 10:12
Show Gist options
  • Save robneu/5789325 to your computer and use it in GitHub Desktop.
Save robneu/5789325 to your computer and use it in GitHub Desktop.
Automatic cache busting in the Genesis Framework based on the last time the file was modified.
<?php
// Remove the default Genesis child theme CSS
remove_action( 'genesis_meta', 'genesis_load_stylesheet' );
add_action( 'wp_enqueue_scripts', 'prefix_load_stylesheet' );
/**
* Get the time the theme's CSS was last modified
* and use it to bust the cache by appending
* it to the CSS output.
*
* @author FAT Media
* @link http://youneedfat.com
*/
function prefix_load_stylesheet() {
// Get the stylesheet info.
$stylesheet_uri = get_stylesheet_directory_uri() . '/style.css';
$stylesheet_dir = get_stylesheet_directory() . '/style.css';
$last_modified = date ( "h.i.s", filemtime( $stylesheet_dir ) );
// Enqueue the stylesheet.
wp_enqueue_style( 'prefix-styles', $stylesheet_uri, array(), $last_modified );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment