Created
June 18, 2018 16:33
-
-
Save CapWebSolutions/a6f3686bd5a13c88ba2617b82fb3a43b to your computer and use it in GitHub Desktop.
Auto cache busitng on css and js based on file time stamp.
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
| /** | |
| * Never worry about cache again! | |
| */ | |
| function my_load_scripts($hook) { | |
| // create my own version codes | |
| $my_js_ver = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'js/custom.js' )); | |
| $my_css_ver = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'style.css' )); | |
| // | |
| wp_enqueue_script( 'custom_js', plugins_url( 'js/custom.js', __FILE__ ), array(), $my_js_ver ); | |
| wp_register_style( 'my_css', plugins_url( 'style.css', __FILE__ ), false, $my_css_ver ); | |
| wp_enqueue_style ( 'my_css' ); | |
| } | |
| add_action('wp_enqueue_scripts', 'my_load_scripts'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment