How To Add Canonical Tag In Magento 2

How to Add Canonical Tag in Magento 2: What is The Best Way

by admin

This article will show you how to add Canonical Tag in Magento 2 stores.

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 can cause significant issues. Google or other search engines will be unable to determine which version of the content is the original or most authoritative. This can lead to unwanted behavior such as lower rankings for both pages or, worse, content being ignored altogether.

To solve this, setting canonical URLs is an effective way to address duplicate content issues and tell Google which URL is authoritative (canonical) for that page. Let’s dive in!

Magento 2 Canonical Tags – The Definition and Role

What is a 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 on your site at a high ratio, Google may penalize your domain and decrease its ranking. For an eCommerce site like Magento 2, this is a common problem because of the high variation in URLs.

There are 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 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.

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!

How To Add Canonical Tag In Magento 2 Product Pages and CMS Pages

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 add canonical URL in Magento 2 product pages.

Magento, however, doesn’t. Magento’s admin panel lets you Magento 2 set canonical URL 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

magento-2-canonical-tag

2. Then choose Catalog > Catalog

magento-2-canonical-tag

3. Apply Canonical Tags

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

magento-2-canonical-tag

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 into a magnificent one!

Insert Magento 2 Canonical URL CMS Page

Here are some steps to Magento 2 add canonical tag into CMS Pages. You can also add the canonical URL to the homepage in this way.

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">

<head>

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

</head>

</page>

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

A Better Approach with Magento 2 SEO Extension Suite

How to add canonical tag in Magento 2 with Magento 2 SEO extension

The Ultimate SEO Magento Suite helps you to place the canonical tag automatically without any help from the developer. You can choose to set the canonical tag as follows

1. 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 the category
  • Magento 2 Canonical Tag for category page

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

2. Magento 2 Canonical Tag for Homepage

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)

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

If you are new to Magento, check out a comprehensive Magento tutorial for beginners to get a solid foundation and understand the platform’s capabilities fully.

Conclusion

Using canonical tags properly ensures that search engines understand your content hierarchy and preferences. That leads to better SEO outcomes and a more efficient crawl budget utilization. Hope that the guide on how to add canonical tag in Magento 2 by BSS Commerce can help you avoid potential penalties for duplicate content and improve crawling efficiently.

Additionally, utilizing Magento 2 SEO Suite is also a smart way to insert canonical URLs into your Magento 2 store. Contact us if you need more information about web development or plugins for Magento. We are willing to support you every time.

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.