Force WordPress theme CSS changes immediately

| May 5, 2009 | Leave a Comment

Theme authors: if you’ve been tweaking a WordPress site’s CSS file, the changes you’ve made usually don’t immediately show up for the blog visitors without a forced refresh. The reason: web browsers usually keep cached copies of site files. Mark Jaquith has a neat fix that allows you to grab the latest version of the CSS file and override the cached one automatically.

Just use this line of code in your header.php file:

<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/style.css?v=<?php echo filemtime(TEMPLATEPATH . '/style.css'); ?>" type="text/css" media="screen, projection" />

This automatically updates the ?v= part every time you modify the file. Boom. Now everyone instantly sees your changes.

This should also work for other files like your Javascript files.

Related Posts

Tags: , , , , ,

2 Comments

  1. links for 2009-05-05 en newdisco Said,

    […] Force WordPress theme CSS changes immediately | WordPress Philippines Como forzar la actualización de CSS cuando haces cambios en un theme. (tags: wordpress hack howto css theme template) Archivado en:   |   Search […]

  2. Edward Palomo Said,

    This is what I’m looking for… since many of my blog’s visitors don’t know the word cache…LOL

    Edward Palomo´s last blog post: My struggle to get it right: a novice web designer’s dilemma over browser compatibility issues

RSS feed for comments on this post · TrackBack URI

Leave a Reply