It is very common for duplicate pages to be inadvertently created on websites, especially on ecommerce sites, but this could harm your Google rankings, which is where canonical tags come in.

It is commonplace on Magento ecommerce sites for products to be added under more than one category, or for categories to be added within different areas of the site. Adding products under multiple relevant categories or categories within different areas of the site makes perfect sense, as it increases visibility, but it can confuse Google and harm your rankings.

The good news is that canonical tags can be added to pages to tell Google which is the preferred page that you want to rank for. Configuring Magento canonical tags is important as it will combat duplicate content your website(s). In this post, I take a look at how to add canonical tags in Magento, one of the most commonly used website ecommerce platforms.

Setting Up Magento Product Canonical Tags

Within Magento you can set up canonical tags for product pages so that the URL you would like to rank is always the URL of the product without any of the category paths. For example, by using a canonical tag you could instruct Google that you want to index the page URL highlighted in italics out of the list of pages shown below:

To set the canonical tag to default to your product page name, without the categories, complete the following steps:

  1. Login to Magento and go to the configuration settings

Login to Magento and select the System menu (far right) and select Configuration from the drop down (last option in list).

Magento 1.0 system configuration options

  1. Go to the Catalog page

Once you are on the Configuration screen, select the Catalog menu option on the left.

  1. Go to the Search Engine Optimisations settings

Click on the Search Engine Optimisations heading on the catalogue page.

setting magento product canonical tag default

Make sure that the Use Canonical Link Meta Tag for Products and Categories are set to Yes and click save.

It is important that you do not change the Use Canonical Link Tag for Products field to No, if it is already set to yes. Doing so will destroy your SEO as there will be multiple URLs pointing to product pages. Without product page canonical tags Google will not be able to work out which page you want to rank.

How to Set Up Canonical Tags in Magento for Category Pages

Setting up canonical tags for category pages in Magento is not quite as straight forward as it is for products. You can allow Magento to set the category page canonical tags for you, using the Use Canonical Link Meta Tag for Categories drop down option on the Search Engine Optimisation tab on the Catalog page, but this will include self referencing canonical tags. To resolve any competing categories, you will override to override this using the custom code explained below.

Manually Setting Up and Managing Canonical Tags in Magento

1. Select the Category Page that You Want to Add a Canonical Tag to

To add a canonical tag to a Magento category page, go to the category page that you would like to add the tag to. To do this, Select Catalog from the menu and click on Manage Categories.

Manage categories in Magento

2. Select the Custom Design Tab

Select a category and then click on the Custom Design Tab.

4. Go to the Custom Design Custom Layout Update Box

Navigate to the Custom Design, Custom Layout Update box on your category page.

Enter the following canonical tag code in the Custom design box on a Magento category page


In the Custom Layout Update box add the code below to remove the current self referencing canonical tag. Enter the URL that you would like to remove within the area highlighted in bold below.

<reference name=”head”>
<action method=”removeItem”>

The next bit of code is where you specify the canonical tag that you would like to add to the category page. Enter your URL in the area marked in bold to the page to point to the category page on your site that you do want Google to Rank.

<action method=”addLinkRel”>

Essentially, your completed code should resemble the following example code:

<reference name=”head”>
<action method=”removeItem”>
<action method=”addLinkRel”>

Click Save Category and then view the source code to check the code looks correct. You should see the following code in the source code of you category page.

<link rel=”canonical” href=”” />

Alternatively if you are getting an XML error when trying to save, you will need to replace the quotation marks used within the code as manually as copying them from this web may change them to non xml compliant code.


The advantage of manually setting canonical tags in Magento, is that you can now successfully manage duplicate categories on your website. The downside is that if you have many duplicate categories it may take you a while to set this up on every category page.

I do recommend that you invest the time and effort to deal with duplicate categories in this way as the benefits are worthwhile, as you should see an improvement in the organic performance of your site.


19 responses to “How to Add Canonical Tags in Magento”

  1. andy says:

    Hi Peter thank you this article is great as we have the same products under 3 different categories for babies, gifts and Brands. Just one question in the custom layout box does it matter if I use the http:// version of the product page or the https:// version or do i need to put in both? Many Thanks Andy

    • Susan Hallam Susan Hallam says:

      Hi Andy
      Pete’s on holiday, so I thought I would jump in with a reply
      In the Custom Layout box you want to use the version of the URL that you want to rank in Google.
      So, if your primary domain for ranking purposes is https:// then use that version.
      You will not want to use both versions; the redirect from http: to https is handled differently.
      Keep in mind that https:// is now a Google ranking signal, so you may want to migrate if you haven’t done so already.
      Here’s how

  2. andy says:

    Thanks for jumping in and the quick reply Susan – I just tried the code using our https address under ‘soft toys’ category / ‘baby & toddler’ subcategory and magento gives me ‘XML data is invalid’ and wont save it. We are on magento 1.9 do you know why this could be? It would be great if i can get this to work as we have Jellycat under 3 subcategories currently and I am sure we can improve position with this in place. Thanks Andy

    • Pete Keyworth Pete Keyworth says:

      Hi Andy

      I’m sorry to hear that the code didn’t work for you. Did that code that you entered look like the example below?

      Adding a Canonical tag in Magento for a soft toys category


  3. Sorry, but it doesn’t seem clear if we add a category URL in above method then this could be done for one category only? How we will do this for other categories? How we can apply canonical tags for products with category paths?

    • Pete Keyworth Pete Keyworth says:

      Hi Navin

      You would need to add a canonical tag for any category that is a duplicate or targeting the same keywords. To spot duplicate categories on a Magento site, you should look for any categories that are referenced under multiple locations within your navigation.

      Unless you have a customised navigation, the default behaviour of Magento is to create duplicate URLs whenever you add a category added under multiple locations. To make this a bit clearer, if you added a category called Beds under your Furniture category, and added it again under your Bedrooms category, the default Magento behaviour would be to create two pages with two different URLs. In this example the URLs would be:

      To fix any duplicate category issues, you would need to use canonical tags as outlined in the Manually Setting Up and Managing Canonical Tags in Magento section above.

      To resolve the issue with product pages appearing under multiple categories and potentially creating duplicate product page URLs, you should follow the steps explained under the Setting Up Magento Product Canonical Tags at the top of this post. There is a setting within Magento that enables you to enable the Use Canonical Link Meta Tag for Products setting that sorts out any duplicate product URL issues for you. Turning on this setting means that any product URL with a category in front of it, for example /bedrooms/beds/kingsize-tempur-bed.html would automatically include a canonical tag that points to a product page URL off the route of the site without any categories in from of it. For example /kingsize-tempur-bed.html.

      I hope this explains things?


  4. Nicolas says:

    Hello Pete, I tried your approach and I’m getting the same error as Andy. “XML data is invalid.”

    Is there a solution? I am on Magento Ver.

    This is what I add to the Custom Layout Update Box:


  5. Nicolas says:

    This message system didn’t allow me to add the code so that you could see it.
    It switched it to:

    But I added it correctly. Any solution?

    • Pete Keyworth Pete Keyworth says:

      Hello Nicolas

      If you are having trouble using the code suggested then you can enter the html canonical tag directly within the Custom Layout Update Box.

      This would be as follows with the URL included within the being the URL of the page that you would like to rank.

      Adding canonical tag html code to a Magento category page

  6. mari says:

    To avoid the “XML data is invalid.” error try replacing the quote ( ” ) sign manually, as follows:


  7. Hello Pete,
    Such a nice blog with quality knowledge, for me I face little problem in adding canonical tags in Magento. You provide very good information by your blog, keep up the good work.
    Thank you

  8. Mathieu says:

    Hi, just had the same error. When copying code from your post, double-quotes are invalid. Replace with real double-quotes and your XML will save correctly.

    • Pete Keyworth Pete Keyworth says:

      Thanks for your helpful comment Mathieu.

      The code I entered on this post is changed by the CMS as so when copying the code you do need to replace the quotation marks manually.

  9. L. Stassar says:

    Hi there,

    I would like to add the canonical tag to the homepage to avoid duplicated homepage versions like www. and http:// version. For this webshop we use a Magento template: Could you tell me where to add this tag?

    • Pete Keyworth Pete Keyworth says:

      Adding a canonical tag to sort out www. and non www. duplicates isn’t the best approach to resolving this particular type of of issue. The examples you have given are what I would call preferred domain duplicate URLs. These are best handled using 301 rewrite rules to rewrite any URL to match you preferred domain version.

      If you want to only allow users to be able to view www. pages on your site, you would need to setup a 301 rewrite rule to force any URL without the wwww. to go to the www. page version.

      An example of this would be to redirect to go to

  10. Hi! This might be the closest thread I found to the issue I am having with optimization, so I will post here! Thanks to the Amasty extension I have created pages based on categories and attribute values. For example I have created a page based on Category: “Climbing Shoes” and attribute value: “Brand=SCARPA”. Unfortunately the pages are not being indexed and they are therefore not seen as static pages. Is there a way I can solve this?
    Thank you and keep up the good work!

  11. Jackie says:

    Thank you so much for this helpful article! I was working on this and had to do some digging and troubleshooting because (of course), just copying and pasting did not work for me.
    I wanted to pass along some of the additional troubleshooting that I needed to do so that this awesome article can be even better.

    Here are the issues I ran into:
    Received an ‘xml data is invalid’ error message after entering code in Custo Layout Update in Magento
    – As mentioned above, deleting the parenthesis and simply retyping them manually fixed this issue

    I have my ‘Use Canonical Link Meta Tag For Categories’ turned on because my site creates new URLs with every ‘shop by’ option selected, and this creates canonical tags for those situations.
    What I found with this (and what many people found– as mentioned about) was that then there were 2 URLs. One that was auto-generated from the Catalog SEO settings, and one from my manual code in the Custom Layout Update section of the category.

    I tried the code:


    I also tried:


    But neither were removing it.
    I then found this forum-
    With the answer I needed.

    I added in another snippet after the first action method=”removeItem” snippet:


    So my final code looked like this:




    This code worked for me! Not sure why this additional snippet changes it but in the forum, user 7ochem says ‘The only reason I can think that this works is that the removeItem action is looking for the URL before the URL rewrite kicks in. Don’t quote me on that though :)’
    …so this is me quoting him because I also don’t know!

    Hope this helps others!

  12. Is it possible to create canonical links from one domain I own to another? I have a use case where I might want to show product 123 on 2 separate domains (Site and Site I’d like the products on site to have the canonical link pointing back to Site

Leave a Reply

Your email address will not be published. Required fields are marked *