Set "target=_blank" for external urls in child theme? #588
-
Is there a way to make the external links open in a different tab automatically? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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 <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 <a target="_blank" rel="noopener" class="nav-link ps-0 py-1" href="{{ .URL | relURL }}">{{ .Pre | safeHTML }}<small class="ms-2 d-md-none">{{ .Name | safeHTML }}</small></a> |
Beta Was this translation helpful? Give feedback.
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:See also:
For links in menus, you could update the corresponding layout partial, e.g. change
./layouts/partials/header/header.html
(line 46) to: