Open external links in a new tab

You can add some code to your theme that will cause any external links on your online store to open in a new browser tab. This can be beneficial because it helps to prevent customers from navigating away from your online store. External links are URLs that direct customers to different websites, such as the links included in social media icons.

Add some code to your theme's JavaScript file

To have external links open in a new browser tab, you will need to edit your theme's JavaScript file:

  1. Find the theme you want to edit, and then click Actions > Edit code.

  2. In the Assets directory, click one of the following:

    • theme.js
    • theme.js.liquid
    • custom.js
  3. Paste the following code at the bottom of the file:

    $(document).ready( function() {
    jQuery('a[href^="http"]').not('a[href^="'+$(location).attr('hostname')+'"]').attr('target', '_blank');
  4. Click Save.

Ready to start selling with Shopify?

Try it free