Catalogsearch Meta-Tags – Where to Set Robot Tags for Category and Tag Pages

catalogsearchmeta-tagstags

when I try to set the robots tags by xml or programatically in _preparelayout, it doesn't work. Instead they are always NOINDEX, FOLLOW. This also happens for categorysearch but I cannot find the code where the robots-tags are changed and actually set.

in local.xml I tried:

<tag_product_list translate="label">
        <label>Tagged Products List</label>
        <!-- Mage_Tag -->
        <reference name="head">
        <action method="setRobots"><value>INDEX,FOLLOW</value></action>
    </reference>
</tag_product_list>

in Tag/Block/Product/result.php I tried

$head = $this->getLayout()->getBlock('head');
$head->setDescription($description);
$head->setRobots('index, nofollow');

Setting the description works fine. But the robot-tags are always set to NOINDEX,FOLLOW.

Can anyone tell me, where the robot-tags for tag pages or catalogsearch pages are set?

Thanks

Best Answer

Create your custom module to do so.
app/code/local/Custom/MetaChange/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Custom_MetaChange>
            <version>1.0.0</version>
        </Custom_MetaChange>
    </modules>
    <global>
        <models>
            <metaChange>
                <class>Custom_MetaChange_Model</class>
            </metaChange>
        </models>
    </global>
    <frontend>
        <events>
            <controller_action_layout_generate_xml_before>
                <observers>
                    <noindex>
                        <type>singleton</type>
                        <class>metaChange/observer</class>
                        <method>changeRobots</method>
                    </noindex>
                </observers>
            </controller_action_layout_generate_xml_before>
        </events>
    </frontend>
</config>

app/code/local/Custom/MetaChange/Model/Observer.php

<?php

class Custom_MetaChange_Model_Observer extends Mage_Core_Model_Abstract {

    public function changeRobots($observer) {

                if ($observer->getEvent()->getAction()->getFullActionName() == 'catalogsearch_result_index') {
                $layout = $observer->getEvent()->getLayout();
                $product_info = $layout->getBlock('head');
                $layout->getUpdate()->addUpdate('<reference name="head"><action method="setRobots"><value>NOINDEX,FOLLOW</value></action></reference>');
                $layout->generateXml();
            }
    }
}

Please create your module activation file.
What I think that you are trying to change robots tags after xml has been generated, you need to do it before xml is generated.
Hoping this will help you.

Related Topic