← Back Home

Open Hugo Links in New Tabs Using Target _Blank

  1. static website
  2. hugo
  3. partials

Motivation

By default Hugo links drive visitors off your website. I don’t like that so I figured out how to open links using target="_blank".

Change the Default Markup

In your Hugo theme add the file themes/your-theme/layouts/_default/_markup/render-link.html and make it look like the this.

<!-- themes/your-theme/layouts/_default/_markup/render-link.html -->
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} rel="noopener noreferrer" target="_blank"{{ end }}>{{ .Text }}</a>

Now all links will open in new tabs.

Subscribe to my newsletter!