Skip to content

Commit

Permalink
Merge pull request #376 from aurooba/patch-2
Browse files Browse the repository at this point in the history
Add cache busting to styles and scripts enqueue
  • Loading branch information
bacoords authored Feb 2, 2023
2 parents 8555f79 + be33c1e commit bd51bae
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,22 @@ function understrap_remove_scripts() {
function theme_enqueue_styles() {

// Get the theme data.
$the_theme = wp_get_theme();
$the_theme = wp_get_theme();
$theme_version = $the_theme->get( 'Version' );

$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
// Grab asset urls.
$theme_styles = "/css/child-theme{$suffix}.css";
$theme_scripts = "/js/child-theme{$suffix}.js";

$css_version = $theme_version . '.' . filemtime( get_stylesheet_directory_uri() . $theme_styles );

wp_enqueue_style( 'child-understrap-styles', get_stylesheet_directory_uri() . $theme_styles, array(), $the_theme->get( 'Version' ) );
wp_enqueue_style( 'child-understrap-styles', get_stylesheet_directory_uri() . $theme_styles, array(), $css_version );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'child-understrap-scripts', get_stylesheet_directory_uri() . $theme_scripts, array(), $the_theme->get( 'Version' ), true );

$js_version = $theme_version . '.' . filemtime( get_stylesheet_directory_uri() . $theme_scripts );

wp_enqueue_script( 'child-understrap-scripts', get_stylesheet_directory_uri() . $theme_scripts, array(), $js_version, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
Expand Down

0 comments on commit bd51bae

Please sign in to comment.