How can I set up a category that links to an external site

Last updated

If you want some category in Ecwid to link to an external site or to a separate page of your site, you just need to add a special JavaScript code after the Ecwid integration code on the page where your store is installed. This code uses the Ecwid Javascript API for handling the Ecwid 'OnPageLoad' event and redirecting your visitors to an external page if they try to open some particular category in Ecwid.

Please see this code below. ​

This code works for any Ecwid store, however the very first part of it should be modified to fit your exact needs. The part which requires modifying is this one:

var categoryURLs = {
  '22791643' : '',
  '1797366' : ''

// Add handler for Ecwid's OnPageLoad event
if (
  typeof(Ecwid) == 'object'
) {
  Ecwid.OnPageLoaded.add(function(page) {
    // Redirect user if needed
    if (
      typeof(page) == 'object'
      && 'CATEGORY' == page.type
      && typeof(categoryURLs[page.categoryId]) == 'string'
      && categoryURLs[page.categoryId].length > 0
    ) {
      window.location = categoryURLs[page.categoryId];

In order to set redirection rules for your store you should edit the 'categoryURLs' variable. In the example above:

- 1765387 and 1797366 are the IDs of categories which should link to external pages;

- '' and '' are those pages.

  1. To get the ID of the category you want to set as a link in your store please refer to this article
  2. When you edit the list of category URLs please make sure that each URL is properly enclosed in quotation marks and each line ends with comma except the last line.

You can use the code above on all of your storefronts because category IDs remain the same for all of them. Moreover, since it is not changed from one storefront to another, the best way to use it is to place it in a javascript file (with a .js extension) and call this file on multiple pages instead of pasting the code into pages one by one.

You can use the following js file as a base for your own one:

To make it work please do the following:

  1. Download this javascript file.
  2. Modify redirection rules as I described earlier in this post.
  3. Place it somewhere in the web with public access.
  4. Specify the location of the external JavaScript file on the page you want it to be executed on by appending a link to it to your Ecwid integration code. Such a link should look like this:

<script type="text/javascript" language="javascript" src="">

where "" should be replaced with the location of the file.

The described method (with inclusion of a js file) is also recommended for Wordpress users. The Wordpress editor that is used to edit the source code of Ecwid shop page parses JavaScript codes incorrectly. So it is safer to use the script in the external file as described above, even if you use the WP 'ecwid-shopping-cart' plugin for your store integration. You need to find a page where your Ecwid store is installed (it can be found under the 'Pages' tab in your WP admin panel, usually it is called Store), edit it, switch to HTML editor and insert a link to your external JavaScript file into its source after all the Ecwid integration codes.

There is also a more simple way to make the links in the category listings by adding those links into the category description (see Ecwid control panel → Catalog → Categories, select the category you need and edit the description in the Category description area at the bottom). But this way your custom links will appear above all the other category contents and not among the other subcategories.

​For product details

You also can use this solution, if you need to redirect customer to another page upon visiting the products details page of a particular product. You just need to change the code above a bit. Change “CATEGORY” to “PRODUCT” in this line

&& 'CATEGORY' == page.type

so that it reads as

&& 'PRODUCT' == page.type

change “page.categoryId” variable to “page.productId” in the code, and of course use the product IDs instead of category IDs accordingly.

Back to top
Has the article answered your question?

Awesome! Thanks for your feedback!

Please send us that question. We will be happy to help by email.

Send a message