I'd like to add versioning to the custom.css file - but I'm not sure where it's loaded (this is for the gazette template). Could you point me in the direction of the file that does this?
Solved
Templates
Where to edit the reference to custom.css
Accepted answer
Marked as the solution
Rashida Rahman Staff
Hi,
Thanks for reaching out.
custom.css is loaded in templates/shaper_gazette/index.php, around line 133:
$theme->add_css('custom');
To add versioning, replace that line with:
$customCss = JPATH_THEMES . '/' . $this->template . '/css/custom.css';
$theme->add_css('custom.css', ['version' => file_exists($customCss) ? filemtime($customCss) : 'auto']);
This adds the file's last-modified time as the version (e.g. custom.css?1793617150). It updates automatically every time you save custom.css, so browsers always load the latest copy with no manual changes.
Please note:
- The version is only for browser cache-busting. It doesn't keep previous copies of the file, and Joomla doesn't store a history of template files. To roll back, use a backup (e.g. Akeeba Backup), Git, or a copy saved before each change.
- The stylesheet is only loaded if
templates/shaper_gazette/css/custom.cssexists. - A template update will overwrite
index.php, so keep a note of this change.
Let us know if you need any further help.
Best regards
2 more replies
Gavin J Hanly Asked this
Great - that works perfectly - thanks for the quick reply!
Paul Frankowski Senior Staff
You can also use another trick https://www.joomshaper.com/documentation/helix-framework/custom-code-css-js-meta#documentation-heading-3 read after the 2nd screenshot "If somehow your custom.css file in the HTML ..."
Log in to reply.