Created
April 10, 2019 15:30
-
-
Save brianpurkiss/0aa7470a0d9e24d341471cab58034f24 to your computer and use it in GitHub Desktop.
Auto clear visitors' cache by auto incrementing version based on theme version number
This file contains hidden or 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 | |
/** | |
* Enqueue CSS & scripts file | |
* The "Cache Buster" appends the theme version number as a ?ver= | |
* The "Cache Buster" auto increments whenever the theme's version number increments | |
* This gets visitors to load the new CSS/JS whenever the theme updates | |
*/ | |
function bp_enqueue() { | |
// Increments the version number for css/js based on the theme's version number | |
// Increment the theme version number to reset the cashe for the site files | |
$cache_buster = wp_get_theme()->get('Version'); | |
wp_register_script('bp-scripts', get_stylesheet_directory_uri() . '/scripts.js', array(), $cache_buster, true); | |
wp_enqueue_script('bp-scripts'); | |
// Main stylesheet | |
wp_enqueue_style('bp-styles', get_stylesheet_directory_uri() . '/style.css', array(), $cache_buster); | |
} | |
add_action( 'wp_enqueue_scripts', 'bp_enqueue' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment