How to Prevent CSS Stylesheet Caching in WordPress

Whether you’re in the development stage or making updates to an existing WordPress project, you may run into unwanted stylesheet caching. In an effort to reduce server hits, WordPress automatically caches the stylesheet. While this is great under normal circumstances, it’s not ideal when you want to see the immediate effect of a CSS change. In this tutorial we will teach you a very simple one step method to temporarily prevent WordPress from caching your stylesheet.

Add a Timestamp to the End of the Stylesheet HTML Link Tag

Simply replace your CSS stylesheet HTML link tag located in the HEAD section of your document with the code below.

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?> ?<?php echo time(); ?>" type="text/css" media="screen" />

How does this work?
Adding the timestamp to the stylesheet HTML link tag means that the CSS file is fetched ‘new’ on each pageload.

Don’t forget to remove the timestamp from your stylsheet HTML link tag when you’ve finished your updates or development to allow WordPress to resume normal caching again.


If you are having problems getting this tutorial to work please reread the tutorial and try again, if you still cannot get it to work please leave us a comment below and we will respond as soon as possible. Please do not email us with problems regarding this tutorial, only comments will be responded to.