How to Open External Links in a New Tab on Shopify

The one piece of code I add to every store to keep customers from leaving the website.

How to open external links in a new tab on Shopify

You always want external links (any links that lead outside of the store's URL) to open into a new tab so that customers don’t completely leave the website and never come back. Most stores have external links going to social media content, press releases, or stockist locations.

To keep website visitors on the store’s website (while still giving them the opportunity to browse elsewhere), make sure to add this piece of code to every store you work on.

This code will make sure external links open in a new tab. The code is originally from the Shopify Help Center here.

  1. Go to Online Store > Themes > beside the theme you want to edit, click … > Edit Code.
  2. In the file search bar, search for .js and scroll down to the in the Assets folder. Look for a file that represents the main JS file or custom JS file if it exists. For example, theme.js, global.js or custom.js. Open this file.
  3. Scroll all the way down to the bottom of the file, and paste the below code. Click Save.

If the code is not working as expected, it could be that you're in the wrong file. Open theme.liquid and check which JS files are being imported. You'll want to add it to the first or second JS file being imported. 

You may also have to make some small tweaks unique to the theme you're using. For example, in the Broadcast and Palo Alto themes, after adding code to the custom.js file, you need to do an addition step. Open the theme.liquid file and search for custom.js. You'll see that there's a note that says you need to import the custom.js file by cutting and pasting a line of code to move it outside of the comment.

Shopify Broadcast theme custom.js comment

Now you don't have to worry about customers leaving the site due to outbound links!

Shopify External Links FAQ

Should external links open in a new tab?

Yes, external links should open in a new tab so that users do not leave the website they initially set out to visit. For example, Shopify store owners should have their social media links open in a new tab so that customers stay on the website to browse even after visiting the social media profile.

How do I make external links open in a new tab on Shopify?

When adding a link to a section or piece of text, some themes offer a checkbox to set "Open this link in a new window". In order to not have to worry about remembering to select this every time, you may add a small snippet of code to your theme to ensure that all external links open in a new tab. The code snippet is above in this article!


Try Shopify for just $1 today.


Enjoyed this post?

Watch our
Free Training

Watch now
Free Shopify Training for Designers