Skip to content

Set "target=_blank" for external urls in child theme? #588

Discussion options

You must be logged in to vote

I advise you to open external links in a new window or tab only when necessary — for UX reasons mainly, see also G200: Opening new windows and tabs from a link only when necessary

For all external links in the content, you could create a file ./layouts/_default/_markup/render-link.html, and add:

<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>

See also:

For links in menus, you could update the corresponding layout partial, e.g. change ./layouts/partials/header/header.html (line 46) to:

<a target

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by iamsantanubanerjee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants