0

How to add noindex,follow to category sorting pages? For example a category sort by high price or low price.

How do I add noindex,follow to this sort result.

0

You can achieve via event.

Fire an Observer on layout_load_before.

On This observer Change robot value to noindex,follow when url has query param product_list_order.

Define Observer:

Define observer at app/code/{Vendorname}/{Modulename}/etc/events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="layout_load_before">
        <observer name="add_robot" instance="{Vendorname}\{Modulename}\Observer\NoindexfollowOnCategory" />
    </event>    
</config>

Observer Class:

<?php
/**.
 * User: Amit
 * Date: 10/29/2017
 * Time: 12:34 AM
 */

namespace {Vendorname}\{Modulename}\Observer;
use Magento\Framework\Event\ObserverInterface;

class NoindexfollowOnCategory implements ObserverInterface
{

    protected $request;

    protected $layoutFactory;

    public function __construct(
    \Magento\Framework\App\Request\Http $request,
    \Magento\Framework\View\Page\Config $layoutFactory
    ) {
        $this->request = $request;
        $this->layoutFactory = $layoutFactory;
    }



    public function execute(\Magento\Framework\Event\Observer $observer) {

    $fullActionName = $observer->getFullActionName();

     if ($fullActionName == "catalog_category_view" && $this->request->getParam('product_list_order')
        && !is_null($this->request->getParam('product_list_order'))){
          $this->layoutFactory->setRobots('NOINDEX,NOFOLLOW');
       }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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