Don't show some shortcodes in Hugo's RSS output
So, in many of my blog posts, there’s a podcast version, and I have a little Hugo shortcode to embed those into the page. That was nice - and then I saw the RSS feed for my blog, and all the code (complete with embedded Javascript) was in the page. Yuck.
The solution is relatively easy but not very clearly documented.
Let’s say you have a shortcode like
{{ <cheese-animation large> }}
in your blog post, which will embed a lovely large complex Javascript animation of a block of cheese. That looks lovely on the web, but in an RSS feed, it doesn’t work at all, unsurprisingly.
In order to do that, your shortcode is saved in /shortcodes/
in your theme, and is called cheese-animation.html
. That’s what Hugo calls to make the final assembled HTML page, passing the variable “large” to it.
How do you stop this shortcode output from appearing in the RSS feed of the post?
Make a new file.
Call it cheese-animation.xml
and save it in /shortcodes/
(leaving it blank if you like).
That shortcode will be the one the RSS export tool uses, in preference to the one ending HTML.
The HTML version of your page will still use the one ending .html
.
Hurray!