I'm looking to programmatically get the version of the current public theme (in order to do some automatic "cache-busting").
Ideally, I'd just use the theme object but I've had no luck with that route (e.g. getTheme($themeName)
).
I'd like to avoid manually appending a version to the head CSS with each minor release (since it's easy to overlook). Any thoughts on the best way to do this?
Example: <link href="/myThemeName/css/screen.css?v=myThemeVersion" media="all" rel="stylesheet" type="text/css" >
This is header.php
seemed to output the theme for me:
<?php
$themeName = Theme::getCurrentThemeName();
$theme = Theme::getTheme($themeName);
echo $theme->version;
?>
In case anyone else finds this useful, here's a custom function:
// Get theme CSS link with version number
function get_theme_css($media='all'){
$themeName = Theme::getCurrentThemeName();
$theme = Theme::getTheme($themeName);
return '<link href="'.WEB_PUBLIC_THEME.'/'.$themeName.'/css/screen.css?v='.$theme->version.'" media="'.$media.'" rel="stylesheet" type="text/css" >';
}