Shortcode: Add Raw HTML to Your Posts

☕  Ad-blocker? Consider buying me a coffee instead :)

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
Copy to Clipboard
<!-- raw html -->
{{.Inner}}

Example Usage

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

Output

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