-
-
Save carestad/3841998 to your computer and use it in GitHub Desktop.
Add a query string to the end of the theme's style.css when WordPress is loaded.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add a filter to stylesheet_uri, which appends a query string to it automagically. | |
*/ | |
add_filter('stylesheet_uri', function($css) { | |
$parts = parse_url($css); | |
$file = $_SERVER['DOCUMENT_ROOT'] . $parts['path']; | |
if (file_exists($file)) { | |
$query = array(); | |
if (isset($parts['query'])) { | |
parse_str($parts['query'], $query); | |
} | |
$query['ver'] = filemtime($file); | |
$querystr = http_build_query($query, null, '&'); | |
$user = isset($parts['user']) ? $parts['user'] : ''; | |
$pass = isset($parts['pass']) ? $parts['pass'] : ''; | |
$userpass = (!empty($user) || !empty($pass)) ? $user.'@'.$pass : ''; | |
$css = "{$parts['scheme']}://{$userpass}{$parts['host']}{$parts['path']}?{$querystr}"; | |
echo $css; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment