How to Open External Links in a New Tab on Shopify
A six-line JavaScript snippet that opens every outbound link on your Shopify store in a new tab. Works on Dawn, Sense, and every modern theme.
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 withtarget="_blank".
Where to Paste It Per Theme
- Dawn, Sense, Refresh:
assets/global.js - Older modern themes:
assets/theme.jsorassets/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. It is a tiny conversion rate optimization win, the kind of small friction fix that adds up across a whole store.
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?.
More notes
ShopifyWhy Modern Shopify Themes Win for Ecommerce
Shopify rebuilt its theme engine in 2021 and the gap with WordPress widened. Here are four reasons modern Shopify themes are the right pick for most stores.
ShopifyHow to Make a Shopify Store Profitable: What to Know First
Most Shopify stores never turn a profit. Here's how to launch faster, market smarter, and cut the costs that quietly eat your margin.
ShopifyShopify's Hidden Features That Quietly Grow Sales
Most Shopify stores use about 30 percent of the platform. Here are the five built-in features I turn on for clients that actually move sales numbers.
ShopifyCan You Use Shopify for Services? Yes, and Here's How
Shopify can run a service business well if you set it up right. Here's how to use apps, CTAs, and Shopify POS to sell services alongside (or instead of) products.
