I want to add canonical tag for all cms pages. Currently canonical tag enabled for category and product page.

How to do this?

4 Answers 4


Go to Admin Panel > Content > Pages > Opne CMS Page > Design > Layout Update XML

Add code in there

      <link rel="canonical" src="www.example.com/page-url-key" src_type="url"/>


To add in Catalog Search Result Page.

Add following code into catalogsearch_result_index.xml in


<referenceBlock name="head.additional">
    <block class="Magento\Framework\View\Element\Template" name="search_canonical" template="Magento_CatalogSearch::canonical.phtml" />

Create PHTML file for canonical URL code.


<link  rel="canonical" href="<?php echo $this->getBaseUrl().'catalogsearch/result/'; ?>" />

Don't forget to flush the cache.

  • It didnt work at first but now it does. Cash has to be flushed and not refreshed. Commented Sep 11, 2018 at 14:35
  • I already mentioned Flush not Refreshed. Glad that It worked :) Commented Sep 11, 2018 at 14:38
  • @AbhishekPanchal, how to include this only on search result page? Commented Dec 18, 2018 at 10:01
  • @jafarpinjar Please check my updated code. Commented Dec 18, 2018 at 14:44
  • @AbhishekPanchal, Thanks i added in default.xml inside catalog_search module. And i can see its working. Commented Dec 18, 2018 at 14:49

You can do it from the Backend in Layout Update XML using the following snippet.

Due the fact that only referenceContainer, container, update, move elements are allowed.

<container name="canonical.url.container">
<block class="Magento\Framework\View\Element\Text" name="canonical.url">
<argument name="text" xsi:type="string"><![CDATA[<link rel="canonical" href="https://example.com" />]]></argument>
<move element="canonical.url.container" destination="head.additional" before="-" />

Use this module for the dynamic canonical link for each cms page-




You can use our extension (Canonical URL extension for Magento 2 by Ecwhim):

It will help you add a canonical url to CMS pages.

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review Commented Feb 1, 2023 at 3:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.