Search code examples
javascriptstatic-sitehugo

How to include simple JavaScript within Hugo


Given the following code:

$('img').mouseenter(function(){
//...
}).mouseleave(function(){
//...
});

I'd like it to be included in my articles. I'd like to avoid editing the theme if possible so to avoid forking etc.


Solution

  • This depends a little on which theme you use. This may be an area where we could do a better job, but do this:

    In the theme, look in the

    layouts/partials folder.

    If you find a header.html or similar, copy this to your local layouts/partials. You can then override the content of this file only. Alternatively you can customize by copying the template used for single pages, often: layouts/_default/single.html.