5

As the title states: How can I add meta noindex to all catalog search result pages in Magento2?

I am hoping for an XML Layout solution.

1 Answer 1

9

To me you can simply create the following files in your module:

  • view/frontend/layout/catalogsearch_advanced_result.xml
  • view/frontend/layout/catalogsearch_result_index.xml

In case of a theme, the file locations will be different, under your theme folder:

  • Magento_CatalogSearch/layout/catalogsearch_advanced_result.xml
  • Magento_CatalogSearch/layout/catalogsearch_result_index.xml

And add the following content to those files (same content for both):

<?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>
        <meta name="robots" content="NOINDEX,NOFOLLOW"/>
    </head>
</page>
1
  • Hi, this works nice for catalogsearch, what about to add noindex to /customer urls?
    – djmzfKnm
    Oct 27, 2020 at 5:30

Your Answer

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

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