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

Notifications You must be signed in to change notification settings

SecuritySense/open-in-blank-markdown-shortcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

open-in-blank-markdown-shortcode

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" "https://github.com/SecuritySense/" >}}

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.

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published