Open external links in a new browser tab or window

Take note that according to most usability experts, opening links in a new browser tab is considered bad practice.

We invite you to read the article Seven tricks that Web users don't know, particularly the section Second browser windows:

"Avoid spawning multiple browser windows if at all possible — taking the "Back" button away from users can make their experience so painful that it usually far outweighs whatever benefit you're trying to provide. One common theory in favor of spawning the second window is that it keeps users from leaving your site, but ironically it may have just the opposite effect by preventing them from returning when they want to."

If you would still like to open external links in a new window, follow these instructions:

  1. From your Shopify admin, click Online Store, and then click Themes (or press G W T).

  2. Find the theme you want to edit, click the ... button, and then click Edit HTML/CSS.

  3. Under the Layout folder, click theme.liquid to open your theme.liquid file in the online code editor.

  4. Locate the closing body tag </body>, which should be near the bottom of the file.

  5. Paste the following code above the closing body tag:

    jQuery('a[href^="http"]').not('a[href^="{{ shop.url }}"]').attr('target', '_blank');
    Add before closing body tag
  6. Save your changes.

Want to discuss this page?

Visit the Shopify Community