Where to edit the reference to custom.css - Forum | JoomShaper
Solved Templates

Where to edit the reference to custom.css

Asked by Gavin J Hanly 2 days ago Last activity 1 day ago

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?

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.css exists.
  • 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!

Rashida Rahman Staff

Hi,

You are always welcome :)

You may accept the most useful answer in order to close the post.

Have a nice day!

Best regards,

Rashida Rahman Staff

Thanks for accepting the answer:)

Log in to reply.