This is an old one, but still a great solution for busting browser cache any time you update your theme stylesheet. Mark Jaquith shows how to easily wrap your stylesheet with filemtime
, a PHP function that returns the time a file was last changed. That way, if the stylesheet loads and the file is unchanged, you don’t re-load it unnecessarily. But if the file has changed, filemtime
will force the browser to reload the stylesheet.
Bill Erickson also created a filter to do the same thing with Genesis themes.
(Here’s some context to the Gist)
When Genesis enqueues the child theme’s stylesheet, it checks to see if ‘CHILD_THEME_VERSION’ is defined. If it is, that is used as the version. If it isn’t, the parent theme’s version number is used (view source on my site to see ?ver=1.91, which is Genesis’ current version).
The code in the Gist sets the child theme version to the last modified date of style.css. So when you modify it, the URL to your stylesheet changes and the cache is busted.
Very nice snippet. I’m using Genesis but I think this can be applied for other themes as well.
VersionIT http://wordpress.org/extend/plugins/versionit/ a plugin I made with w-shadow also does this automatically for you without using query args 😉
I did a similar thing http://tareq.wedevs.com/2013/01/force-javascript-css-reload-in-wordpress/ 😉