Last active
December 17, 2018 10:12
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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