How to Escape Hugo Shortcodes

  • |
  • 11 April 2022
Image not Found

If, for some reason, you need to write a Hugo shortcode on your website, you need to escape or inactivate it.

What’s a Shortcode?

A shortcode is a code, embedded in your Hugo templates, that executes Hugo / Go code:

1
{{< shortcode >}}

You cannot write the shortcode as-is, not even in a code block. If you do, Hugo will execute the shortcode anyway. The only way to avoid execution is to escape the shortcode.

Inactivating Shortcodes

Inactivating a Hugo shortcode is simple. Instead of enclosing it within curly brackets and a < symbol {{<, you add a forward dash and an asterisk */>}}:

1
{{</* snippet code */>}}

This will show up on your page as:

1
{{< snippet code >}}

Easy enough, isn’t it?

You May Also Like