Where can I add tracking code within the element? This is not for Google Analytics, so I can’t use the config.toml file, unless I can use it in a way I do not know about. I would obviously prefer that to editing the theme file, so that I can easily switch themes. Thanks.
That depends on your theme. Some have a special template file where you can add code “right after the
<body>-tag”, in some others you have to add the code by yourself.
- Post your repository here and we’ll have a look if there is an easy place.
- Where should the code go, into the
<body>opens or at the end of
<body>? A good theme will offer these three locations for you.
Thanks. I am currently using this theme: https://github.com/yursan9/manis-hugo-theme
I would prefer to put the tracking code within
use the code button for html-code. that’s this one;
</> on top of this editor when you write a message. Then we can see that you might have written
Assuming you have installed the theme normally (meaning there is a folder
themes/themename with that theme in your repo do the following:
- create a folder layouts in the ROOT DIRECTORY of your website (not the theme) (where the config.toml) is located.
- in there create a folder partials
- in there create a file
- in that file place the content of this: https://github.com/yursan9/manis-hugo-theme/blob/master/layouts/partials/meta.html
- then add your code before
These are the rules:
- Everything in your “local” layouts directory (the one you just created) will overwrite what happens in your theme. To change something from the theme, copy the file in question in the same place in your own layouts directory and Hugo will use that file instead of the theme file
- If the theme gets an update you will have to check if the contents of the original changed or are the same. You might need to copy it over into your modification.
Ah yes, all makes sense. Thank you.