Shortcode: Add Raw HTML to Your Posts

This is part of our Hugo shortcode series.

There are times that your imagination stretches beyond markdown’s capabilities. When this happens it can be easiest to use HTML with your post, but Hugo doesn’t always like this. If we create a shortcode though we can switch between markdown and html easily. As shown below.

File: /layouts/shortcodes/rawhtml.html

1
2
<!-- raw html -->
{{.Inner}}

Example Usage

1
2
3
{{< rawhtml >}}
<p>Welcome to <strong>MakeWithHugo</strong></p>
{{< /rawhtml >}}

Output

1
<p>Welcome to <strong>MakeWithHugo</strong></p>