CSS Cache Buster for WordPress Themes

A little while ago, I expressed my joy at being able to avoid CSS cacheing-related issues on websites that could result in poor user experience, by using the CSS Cache Buster plugin.

Unfortunately, this has stopped working for me :( Not sure if it's the version of WordPress, or because I use child theming now. Either way, the demand for this fix maintained, so I've developed my own function for achieving this (leaning heavily on snippets from around the web, as always).


// Add date-modified query to stylesheet to prevent CSS caching when CSS has changed.
function wpi_stylesheet_uri($stylesheet_uri, $stylesheet_dir_uri){

if (!defined('STYLESHEETPATH'))
define('STYLESHEETPATH', get_stylesheet_directory());

$csslastmodified = filemtime(STYLESHEETPATH.'/style.css');

if (!$csslastmodified == '') {
return $stylesheet_dir_uri.'/style.css?' . $csslastmodified;
} else {
return $stylesheet_dir_uri.'/style.css';
}
}
add_filter('stylesheet_uri','wpi_stylesheet_uri',10,2);

As always, very happy to to be corrected, or for this to be improved upon, but it works great for me :)


Digg This
Reddit This
Stumble Now!
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Buzz this!


Printed from: http://www.divydovy.com/2011/02/css-cache-buster-for-wordpress-themes/. © divydovy 2014

Trackbacks/Pingbacks

  1. xhtml css templates – CSS Cache Buster for WordPress Themes – divydovy | XHTML CSS - Style sheet and html programming tutorial and guides

RSS feed for comments on this post , TrackBack URI

Leave a Reply