Skip to content
Example of a custom markdown shortcode to open a link within a blog post in a new tab as most examples found didn't work with the Hugo markdown engine
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


After some Googling I found that the majority of examples of trying to open a link in a new tab from within a blog article didn't work with the Markdown engine within Hugo.

To that end I have come up with the following custom shortcode to achieve this.

Firstly create a folder named shortcodes in your site layouts folder. The name is case sensitive and yes it does have an s on the end.

Within that folder create an html file with a suitable name, for example open-in-blank.html.

The contents of the html should be as follows:

<a href="{{ .Get 1 }}" target="_blank">{{ .Get 0 }}</a>

When you write your blog article and want the link to open in a new tab you should use the following syntax utilising the name of the shortcode html file you created without the file extension e.g open-in-blank:

{{< open-in-blank "Github" "" >}}

The text between the first quotes is the text that is displayed within the post with the second quoted text being the URL to open.

You can’t perform that action at this time.