Hugo does not open links natively in a new tab. This code will help you to achive that - with one line of code!
- Create
layouts/_default/_markup/render-link.html
- Add this line for pre Hugo 0.96:
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank"{{ end }}>{{ .Text | markdownify }}</a>
or, in case you use Hugo 0.96 or newer:
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank"{{ end }}>{{ .Text }}</a>
That’s all! If you get an error that points to markdownify
- check your Hugo version!
External links will now open in a new tab > Source + Credit - and local links will open in the same tab > brötchen