DocsAspectExternal Links in New Tab

External Links in New Tab

By default in Ghost, all links in your posts are opened in the same browser window. Sometimes you may want to open external links in a new tab. This can be done by adding target="_blank" and rel="noopener noreferrer" attributes to the link.

Code Injection is required to add custom JS.

There is an API in the Aspect theme to add these attributes to all external links. You can use the following code snippet:

<script>
window.pvs?.addExternalLinkAttributes?.();
</script>

This code snippet adds target="_blank" and rel="noopener noreferrer" attributes to all external links. If you want to change the target and rel attributes, you can use the following code snippet:

<script>
window.pvs?.addExternalLinkAttributes?.({
    selector: 'a:not([target="_blank"])',
    target: '_blank',
    rel: 'noopener noreferrer',
});
</script>