Thoughts about tech, programming, Bitcoin, and more.

Open Ghost article links in a new tab

Since moving to Ghost from WordPress last week, I've published a few blog posts and realized that any links I include in my blog posts open in the same tab and take the user away from the blog post.

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.

If a link is outside of the main article content then it should open in the current tab.

So here are a few lines of JavaScript that will modify any links in your article content to open in a new tab.

Visit the Code Injection page in your settings and add it to the Site Footer field.

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

Subscribe to Daniel Lemky

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