Skip to content

Instantly share code, notes, and snippets.

@patric-boehner
Last active November 13, 2015 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patric-boehner/8f9fed7d2014f061959b to your computer and use it in GitHub Desktop.
Save patric-boehner/8f9fed7d2014f061959b to your computer and use it in GitHub Desktop.
Wordpress cache busting while in local development with debug on.

Cache Busting While Debug Is On

A quick way to bust cache of scripts and style sheets in wordpress when debug is on (something you would most likely only be doing when in local development). Sets a new version number every time the page is releated based on the current Unix timestamp, otherwise return a set static number you can manualy update.

Example result in DEBUG mode:

<script type="text/javascript" src="http://localhost/wordpress.../js/scroll-to-top.js?ver=1447394696"></script>

Example result with DEBUG off:

<script type="text/javascript" src="http://localhost/wordpress.../js/scroll-to-top.js?ver=1.1"></script>

Source:

<?php
//* Local development cache busting if debug is on
//* Otherwsie return static number
define ('VERSION', '1.1');
function version_id() {
if ( WP_DEBUG )
return time();
return VERSION;
}
//* Load Login Style
function pb_login_styles() {
wp_enqueue_style( 'login_styles', get_stylesheet_directory_uri() . '/lib/css/login.css', false, version_id() );
}
//* Scroll Back To The Top
function pb_scroll_top_script_enqueue() {
wp_enqueue_script( 'scroll-to-top', get_stylesheet_directory_uri() . '/js/scroll-to-top.js', array( 'jquery' ), version_id(), true );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment