Skip to content

Instantly share code, notes, and snippets.

@nydame
Created October 4, 2018 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nydame/3628c971857027121930dbf6eb4dcb94 to your computer and use it in GitHub Desktop.
Save nydame/3628c971857027121930dbf6eb4dcb94 to your computer and use it in GitHub Desktop.
Conditional cache-busting for WordPress stylesheets
// Tired of making changes to your WordPress site's stylesheet, only to have the client tell you "It looks the same to me!"?
// Force WordPress to send a fresh copy to logged-in users with this simple code snippet.
// (In practice, put this code in your WordPress theme (e.g., in functions.php) or in a custom plugin.)
$now = new DateTime();
$now_version = $now->format('YmdHis');
if (is_user_logged_in()) {
wp_enqueue_style( 'pacificbiosciences-style', get_stylesheet_uri(), array(), $now_version );
} else {
wp_enqueue_style( 'pacificbiosciences-style', get_stylesheet_uri() );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment