Escaping Shortcodes in Hugo

Jun 21, 2018 22:10 · 112 words · 1 minute read

Shortcodes in Hugo bring Go’s powerful templating engine to your Markdown content.

Embedding the source of the shortcodes in posts tutorial-style is not so intuitive. Hugo parses them before parsing any Markdown, so if you just put them as-is inside a code block you will end up with your shortcode being expanded, and the expanded content ending up inside a <pre></pre> block which is probably not what you were after.

There is an undocumented feature that lets you escape your shortcodes so they aren’t expanded however.

{{</* shortcode_name */>}}

The /* */ are stripped out and the rest of the shortcode is all that’s left, and is output as-is:

{{< shortcode_name >}}