0

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

How to do this?

2

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

Add code in there

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

Update:

To add in Catalog Search Result Page.

Add following code into catalogsearch_result_index.xml in

app/design/frontend/Vendor/theme/Magento_CatalogSearch/layout/catalogsearch_result_index.xml

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

Create PHTML file for canonical URL code.

app/design/frontend/Vendor/theme/Magento_CatalogSearch/templates/canonical.phtml

<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. – Code Spirit Sep 11 '18 at 14:35
  • I already mentioned Flush not Refreshed. Glad that It worked :) – Abhishek Panchal Sep 11 '18 at 14:38
  • @AbhishekPanchal, how to include this only on search result page? – jafar pinjar Dec 18 '18 at 10:01
  • @jafarpinjar Please check my updated code. – Abhishek Panchal Dec 18 '18 at 14:44
  • @AbhishekPanchal, Thanks i added in default.xml inside catalog_search module. And i can see its working. – jafar pinjar Dec 18 '18 at 14:49

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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