If you like to tinker around with the style of your theme a lot like I do, you will probably like this article. Our aim is to force the new
style.css file over the old one the users’ cache has. You can do this the dumb-dumb way, the hard way, or the easy way.
The dumb-dumb way is to ignore this issue and wait until the users’ caches expire. Not a very good idea if you ask me.
The hard way is to set some .htaccess expire headers. You can add rules for the CSS to expire every x hours, days, weeks, etc. but I thought we were trying to force the new CSS file right away .
This brings us to the easy way: tweaking the
header.php file a bit! All you have to do is replace your usual style inclusion with a new one. The magic line is:
<link rel="stylesheet" type="text/css" href="<?php echo bloginfo('stylesheet_url'). '?' . filemtime( get_stylesheet_directory() . '/style.css'); ?>" />
After you update your
header.php file you should see something like this when you view the source in your browser:
<link rel="stylesheet" type="text/css" href="http://huzze.net/wp-content/themes/huzze/style.css?1286398426" />
Yeah, the funky numbers after the question mark are the secret.
Simple as that. No more waiting, no more F5, no more nothing. Just a simple click on your “home” button and you will see the changes immediately!