What Is The Best Way To Insert Magento 2 Canonical Tag?

by admin

Having unique content is one of the key factors in SEO. Search engine crawlers take it low on-site with duplicate content (multiple URLs pointing to the same or similar content).

To solve this, you should explicitly tell Google which URL is authoritative (canonical) for that page. If you do not do this explicitly, Google will choose for you or might consider them both of equal weight, which might lead to unwanted behavior.

What is Canonical Tag

According to Rype Wiki, A canonical tag is an HTML specification that appears in the source code of a website’s header area. It refers to the master page, also known as the canonical URL, for websites that contain the same or similar content. 

If a canonical tag is correctly marked, search engines will only index this source, avoiding duplicate content issues. Moreover, the rel=canonical <link> tag can be added to the code for all duplicate pages, pointing to the canonical page.

Why Canonical Tag is important for SEO in Magento 2

If duplicate content is detected in your site at a high ratio, Google may penalty your domain and decrease the ranking. For an e-commerce site like Magento 2, this is a common problem because of the high variation in URLs. With appropriate use of the canonical tag, you can instruct the crawlers which link should be the original and have all the ranking power.

Although canonical tags are the most likely to be used, they aren’t the only technique to declare a canonical URL.

Canonicals may also be set:

  • By setting a rel=canonical HTTP header response
  • Use in your sitemap. However, Google will determine which pages (if any) are duplicates even though all pages mentioned in a sitemap are suggested as canonicals.
  • Use 301 redirects

READ Magento 2 SEO Plugin: Best Practices For Product Pages to gain the most suitable ways which can apply for your store!

What are the most common examples of duplicate content in Magento 2?

There’re 2 common types of duplicate content: partial duplicates and full duplicates:

  • Partial duplicates: When only a small portion of the content or its arrangement is distinctive, there are partial duplicates. The most typical instances of partial duplication in Magento 2 stores can be the same product in different forms or product sorting, etc.
  • Full duplicates: When the text on two or more pages is exactly the same, this is known as a full duplicate. In Magento, full duplicates most frequently appear as the same item in various categories.

How To Add Canonical URLs In Magento 2

Add Canonical Tag To Product & Category Pages

The HTML attribute rel=”canonical” is inserted into the page’s head> tag. Therefore, changing the code is typically necessary to include canonical tags.

Magento, however, doesn’t. Magento’s admin panel lets you set canonical tags for products and categories.

You only need to enable the necessary options for items and categories by the following step.

1. First, navigate to Stores > Settings > Configuration 


2. Then choose Catalog > Catalog 


3. Scroll down to find Search Engine Optimization. Next, enable “Use Canonical Link Meta Tag For Categories” and “Use Canonical Link Meta Tag For Products”.


Canonical tags will be applied to your product and category pages after you select these options.

4. Save Config

Explore our Magento development services to transform your store to the magnificent one!

Add Canonical to CMS Pages

To add the canonical URL to the CMS page in Magento 2: 

1. Create .XML file. For example, cms_page_view_selectable_about-us_test.xml:

  • about-us: is the CMS Page Identifier
  • test: the updated layout. Later, in your Magento Admin Panel, this name will be shown as a list of options.

2. Once the XML file has been created, add the following code to it:

<?xml version=”1.0″?>

<page xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:View/Layout/etc/page_configuration.xsd”>


      <link rel=”canonical” src=”your chosen canonical URL” src_type=”url”/>



3. Put this file in (your_Magento_root)\vendor\magento\theme-frontend-luma\Magento_Theme\layout, and then use the following command to flush the cache:

php bin/magento cache:flush

You can also add the canonical URL to the homepage in this way.

A Better Approach

Magento 2 SEO extension helps you to place the canonical tag automatically without any help from the developer. You can choose to set the canonical tag as following

  • Magento 2 Canonical Tag for product page

The product page URL may have multiple variations. You can set the canonical to either one of these two options:

  • Short URL path: the shortest URL like  https://yoursite.com/
  • Long URL path: the longest URL, containing category
  • Magento 2 Canonical Tag for category page

 CLICK HERE to get The All-in-One Definitive Guide of Magento 2 Seo immediately!

For the category page, we use a specific tag name rel=next and rel=”prev” for the canonical purpose. When implementing this markup, we tell the crawlers to index links, from the component pages/URLs to the series as a whole (i.e., links should not remain dispersed between page-1.html, page-2.html, etc., but be grouped with the sequence)

  • Magento 2 Canonical Tag for Homepage

In case you want to use another URL for canonical of the homepage, admins can use it freely to set one.

magento 2 seo extension

BSS Commerce is one of the leading Magento extension providers and web development services in the world. With experienced and certified Magento developers, we commit to bringing high-quality products and services to optimize your business effectively. Furthermore, we offer FREE Installation – FREE 1-year Support and FREE Lifetime Update for every Magento extension.

CONTACT NOW to let us know your problems. We are willing to support you every time.

NEW: We have launched Trello’s Product Roadmap to keep you updated on our latest product versions. Share your feedback and suggestions for Magento solutions to help us improve your experience here. With our Product Roadmap, you can also request updates or compatibility for your desired modules or suggest a new one to enhance your website.
>> Explore NOW! 

Next Reading Suggestions

© 2019 BSS Commerce owned by THANH CONG INTER ., JSC. All Rights Reserved.
Business registration certificate no. 0106064469 issued by Hanoi Department of Planning and Investment on 19 December 2019.
Legal Representative: Mr. Nguyen Quang Trung.