Featured image of post Prevent Parsing of Shortcodes Inside Code Blocks

Prevent Parsing of Shortcodes Inside Code Blocks

This is how you can show literal shortcodes inside your code blocks. It took me forever to find this!

When writing a post about my Hugo experiences, I came across this issue of Hugo wanting to parse a shortcode in my examples. This one just about drove me insane, but I found the answer here, and thought I should document it for myself and any other Hugo/Markdown noob that comes across this issue. I tried to escape the code \ and even tried to use HTML entity code { and } for the curly braces. The solution, however, is to comment it out:

{{</* shortcode */>}}

Which will be render like this:

{{< shortcode >}}

Using comment syntax allows me to display the shortcode. It effectively treats the shortcode as a comment, so it is not executed or interpreted by Hugo.

Linux, Scripting, and Self-Hosting Projects
Built with Hugo
Theme Stack designed by Jimmy