hugo-saasify-theme icon indicating copy to clipboard operation
hugo-saasify-theme copied to clipboard

how to add custom code to <head>?

Open jkolobok opened this issue 9 months ago • 5 comments

I want to add trackers that are not google analytics, so Just was to be able to easily add code snippets te

on each page. adding something like /layouts/partials/custom_head.html doesn't seem to work

jkolobok avatar Mar 15 '25 00:03 jkolobok

I think google tag manager can create a tag with multiple scripts in it, so you could try that.

Otherwise, you can override the analytics partial

  1. Copy themes\hugo-saasify-theme\layouts\partials\google-analytics.html to layouts\partials\google-analytics.html
  2. Add your tracker code to layouts\partials\google-analytics.html

The GA partial has an if hugo.IsProduction condition so if you put your script inside the if block it won't show when testing locally.

rossdonald avatar Mar 15 '25 03:03 rossdonald

Thanks! #2 helps, but I'd vote for a nicer solution e.g separate file for head, body etc.

jkolobok avatar Mar 15 '25 05:03 jkolobok

The theme author doesn't seem to be responding so we are left with hacks from other users like me 😄

rossdonald avatar Mar 15 '25 06:03 rossdonald

I am back from a trip now. I will add the support of Google Tag Manager container to the solution later.

chaoming avatar Mar 16 '25 07:03 chaoming

Please add something generic for head and footer.

jkolobok avatar Mar 16 '25 09:03 jkolobok