All Notes
Shopify·5 min read·

How to Open External Links in a New Tab on Shopify

Preston Vawdrey

Preston Vawdrey

Full Stack Marketer

Shopify themes ship with almost no JavaScript by default. That is normally a good thing. It keeps page speed high. The downside is that simple front-end behaviors you take for granted on WordPress are not built in. Opening external links in a new tab is one of them.

Here is the snippet I drop into every Shopify build.

The Code

Open your theme's main JavaScript asset file. On Dawn and most modern Shopify themes, that is assets/global.js. Paste this at the bottom of the file:

(function () {
  const links = document.links;
  for (let i = 0; i < links.length; i++) {
    if (links[i].hostname !== window.location.hostname) {
      links[i].target = '_blank';
      links[i].rel = 'noreferrer noopener';
    }
  }
})();

Save the file. Reload your storefront. Every link pointing to a different domain now opens in a new tab.

What It Does

The snippet walks every link on the page. If the link's hostname does not match your store's hostname, it sets two attributes:

  • target="_blank" opens the link in a new browser tab.
  • rel="noreferrer noopener" prevents the new tab from referencing your store and patches a small security issue with target="_blank".

Where to Paste It Per Theme

  • Dawn, Sense, Refresh: assets/global.js
  • Older modern themes: assets/theme.js or assets/theme.js.liquid
  • Heavily customized themes: any custom JS file that runs on every page

If your theme uses a build step (rare on Shopify), paste it into your source file and rebuild. If not, the change is live on save.

Why This Matters for SEO and UX

External links to YouTube reviews, supplier sites, or trust badges send visitors away. If they open in the same tab, most of those visitors are gone for good. Opening them in a new tab keeps your store one click away.

On the SEO side, the rel="noreferrer noopener" part is a small win for security. Without it, the new tab can manipulate the original page via window.opener. Modern browsers default to safer behavior for _blank now, but being explicit is good hygiene.

If you are running a Shopify store and want a tighter take on the platform's SEO trade-offs, I wrote about that in Is Shopify Bad for SEO?.

Let's Work Together

Whether you need a website, marketing strategy, or full-stack growth support, I'd love to hear about your project.