• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Genesis Snippets

A reference for Genesis theme developers

  • Home
  • Archives
  • Search Genesis Snippets

Override CSS cache – Force CSS changes to go live immediately

March 21, 2012 By David Wang

You can prevent web browsers from caching your CSS files by adding a parameter to the end of the stylesheet URI, e.g. ../themename/style.css?v=123. The following is how to do this in Genesis.

/** CSS Cache Buster */
define( 'CHILD_THEME_VERSION', filemtime( get_stylesheet_directory() . '/style.css' ) );

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. The code 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.

Credit: Bill Erickson

———

Update 2014.06.17: The method above declares CHILD_THEME_VERSION a 2nd time which throws a PHP notice in WordPress. If you don’t like that, you can use the following methods instead.

Add filetime parameter to the style.css link

add_filter( 'stylesheet_uri', 'child_stylesheet_uri' );
/**
 * Cache bust the style.css reference.
 *
 */
function child_stylesheet_uri( $stylesheet_uri ) {
    return add_query_arg( 'v', filemtime( get_stylesheet_directory() . '/style.css' ), $stylesheet_uri );
}

Credit: Greg Rickaby

And finally, here’s a method from WP Engineer you can adapt for use in Genesis too: Force Reload of Scripts and Stylesheets in your Plugin or Theme

Filed Under: Genesis Tagged With: cache, css

Reader Interactions

Comments

  1. Nur Furlong says

    August 25, 2012 at 8:34 pm

    This snippet gives me code errors. Does it need any editing to be used?

  2. david says

    August 26, 2012 at 5:38 pm

    What kind of errors are you getting? Usually I just copy and paste the above into my functions.php file and it works fine.

Primary Sidebar

Brought to you by ClickWP
Buy the Genesis Theme Framework

Who’s behind this?

Hi! I'm David and I'm a big Genesis fan. I've been using it in all my projects and have found it to be super powerful.

I started this site to keep track of all the snippets that I've been using in my projects and so that it's easy for me to find them again instead of digging through my old project files.

Help support this site by buying Genesis with our affiliate links. Thanks!

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 354 other subscribers

Browse Snippets

branding cache comments css custom post type doctype entry footer entry header favicon featured image genesis_custom_loop images internet explorer jetpack loop media menu metabox minify navigation oembed page layouts performance plugin integration post thumbnail shortcode sidebars theme options widget areas widgets WooCommerce WordPress
Everything you need to support your online business
Take WordPress further with the Genesis framework

Copyright © 2025 · Genesis Sample On Genesis Framework · WordPress · Log in