Thoughts about tech, programming, and more.

Open links in a new tab for Ghost

Ghost currently doesn't provide the option to set a link to open in a new tab. So in order to do this, a little bit of Javascript is needed.

Here is the code snippet that can be added to your site. To do so, visit the Code Injection page in your Ghost settings and add the following code snippet to the Site Footer field.

<script>
	links = document.getElementsByClassName("gh-content")[0].getElementsByTagName('a')
    for(i = 0; i < links.length; i++) {
        links[i].setAttribute('target', '_blank');
    }
</script>

Personally, I feel it's a better user experience to open links in a new tab when the link is in the middle of a blog post. It gives the user the opportunity to easily return back to the post at the exact place where they left it.

This will modify only links within the article, so links outside of the main article area like your navigation menu will still open in the current tab.

Subscribe to Daniel Lemky

Sign up now to get access to the library of members-only issues.
Jamie Larson
Subscribe