How to Open Shortcode Links in a New Tab in Hugo

Hongtao Hao / 2020-11-11


I’ve talked about how to open links in new tab in Hugo here . But how can we open links in new tab in a Hugo shortcode, for example, Hugo’s built-in shortcode for figure ?

I found the solution here . Thanks to ju52’s answer.

First, copy the original codes of the figure shortcode. Paste them in a new html file named figure.html. Place this file in layouts/shortcodes. Create a folder named shortcodes within the layouts folder if you don’t have it yet.

Then, change this line {{ with .Get "link"}}<a href="{{.}}">{{ end }} to {{ with .Get "link"}}<a href="{{.}}" target="_blank">{{ end }}.

Last modified on 2020-11-12