How to include simple JavaScript within Hugo

Mitchell Currie picture Mitchell Currie · Oct 16, 2015 · Viewed 9.5k times · Source

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.

Answer

bep picture bep · Oct 17, 2015

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.