How to Add Canonical Tags in Magento 2
Looking for ways to add canonical tags in Magento 2?
Follow me till the end of this blog post & get a step-wise method to canonicalize pages in Magento 2..! 🤩
Magento (Adobe Commerce) is an excellent platform that offers high-end customization abilities, making it a premier choice for everyone — from small merchants to enterprise-level businesses. The flexibility of this platform lets the merchants create feature-rich and beautiful online storefronts, leaving no room for improvement from the UI/UX perspective.
Yet this is not enough to run a successful online store. The merchants, quite often, complain about duplicate content issues while using Magento 2 platform. A common advice given by SEO professionals to combat such issues is to canonicalize the duplicate web pages to the main one.
But, how’d you add canonical tags in Magento 2?
Let’s find out…
Table of Contents
- What are Canonical Tags?
- Why Do You Need to Add Canonical Tags in Magento 2?
- Methods to Add Canonical Tags in Magento 2
- Final Words
What are Canonical Tags?
The literal meaning of the word Canonical suggests — it is something that is genuine, authoritative or as per the rules.
In terms of technical SEO, Canonical tags are the HTML tags that inform search engines about the duplicates of certain web pages and help them prioritize the authentic web page for ranking.
According to Moz, “A canonical tag (aka “rel canonical”) is a way of telling search engines that a specific URL represents the master copy of a page.”
Generally, it is used by webmasters to inform search engines about the original webpage on the duplicate ones. It is present in the header of the HTML page, in the format:<link rel="canonical" href="original-webpage-url" />
Suppose we have the following two URLs leading to the same webpage:
- https://example.com/nike-running-tee.html
- https://example.com/mens-tshirts/nike-running-tee.html
Letting the search engine crawl and index the above two pages with no special instructions can confuse them.
The search engine bots may ponder, “Okay, you got two URLs for the same page. But, which one do I need to show to searchers?”
Adding a canonical tag with a link to the original webpage in the header of the duplicate page can solve the issue. In the above case, we need to add <link rel="canonical" href="https://example.com/nike-running-tee.html" />
in the header of the second web page.
Practically, this is the way of telling crawlers — “Hey, the webpage you’re crawling is a duplicate of another page. Please consider this original URL for ranking.”
Why Do You Need to Add Canonical Tags in Magento 2?
Search engines get confused when they encounter the same content on multiple URLs. This is considered a bad SEO practice. In worst cases, they may rank the less important web pages and dump the important ones under the other pages.
The eCommerce sites, quite often, generate different URLs for the web pages. In such cases, proper use of canonical tags can help store owners eliminate duplicate content issues and save their store from penalties.
Consider the following URLs, for example:
https://example.com/men/tshirts.html
https://example.com/men/tshirts.html?product_list_order=price
https://example.com/men/tshirts.html?product_list_order=name
The above three URLs, they all refer to the same category page. Yet, they all differ from the search engine perspective!
Filtering and sorting features on the category pages in Magento 2 append various parameters at the end of the URLs.
In such cases, we need to inform the search engines that these parametrized URLs are nothing but duplicates of the original category pages. This is where the concept of adding self-referential canonicals comes in handy.
There are other such instances where you may require implementing canonicals in Magento 2.
Methods to Add Canonical Tags in Magento 2
Product & Category Pages
Thanks to the in-built features of the platform that lets you add canonical tags in Magento product and category pages.
It is a straightforward process.
Follow the steps mentioned below to implement category and product canonical in Magento 2:
- Step 1: Log into your Magento 2 admin panel, and navigate to Stores > Settings > Configuration. Expand the Catalog section and click on Catalog.
- Step 2: In the catalog settings, scroll down, expand the Search Engine Optimization section, and configure the following options:
- Use Canonical Link Meta Tag For Categories: Enable this option to add canonicals to the category pages.
- Use Canonical Link Meta Tag For Products: Enable this option to add canonicals to the product pages.
- Step 3: Click on the Save Config button at the top right corner to save the changes.
This is how you can add canonicals in Magento 2 product and category pages.
Other CMS Pages
Adding canonicals to Magento product and category pages is possible using the built-in options.
But what about other CMS pages?
Unfortunately, there is no default option in Magento 2 to add canonical to other CMS pages.
But there is a way to do that using a custom layout update. For example, let’s say you want to add a canonical tag to the About Us page, you can follow these steps:
- Step 1: Create file cms_page_view_selectable_about-us_test.xml file. (Here about-us is the CMS page identifier of the page and test is the name of the layout update)
- Step 2: Add the following code:
1234567<?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="add_target_url_here" src_type="url"/></head></page> - Step 3: Put the file into the root\vendor\magento\theme-frontend-luma\Magento_Theme\layout directory and flush the cache.
& that’s it…!
You can also add canonicals to other pages in the same way.
Just change the CMS page identifier and the canonical URL in the code.
Final Words
Canonicalizing can help Google identify the important web pages amongst the duplicate ones. It becomes vital for you to add canonical tags in Magento 2 store if the parametrized URLs of the category pages are being indexed by Google. I hope this blog post has added value to your Magento SEO knowledge.
Up for discussions? Comment down the common issues you’re facing while optimizing Magento 2 store for SEO.
Thanks for reading. 🍀
Shivbhadrasinh Gohil
Shivbhadrasinh is the Co-founder & Chief Marketing Officer at Meetanshi. He leads the marketing team and is the person behind the marketing & branding success of the company. Being a seasoned digital marketer, he has been consulting online businesses for growth since 2010 and has helped 100+ clients with digital marketing success.
He loves sharing tips and insights about the latest digital marketing trends aimed at helping online business owners.
Prev
Solved: Undefined Index: DirectiveName in SimpleDirective.php in Magento 2
Shopify SEO Migration: Best Practices to Minimize Impact
Next