I need to change my meta tag to NOINDEX and NOFOLLOW for particular page (especially in product detail page) in magento 2. I have tried adding
<head>
<meta name="robots" content="NOINDEX,NOFOLLOW"/>
</head>
and also
<reference name="head">
<action method="setRobots"><value>NOINDEX,NOFOLLOW</value></action>
</reference>
In layout update xml but not changing from default how to fix the issue.
P.S.:I need to update via magento 2 backend.
Best Answer
To resolve this issue, you can use event/Observer.
Create a small module.
Fire an Observer an observer on
layout_load_before
event. On this event make product details page isNOINDEX,NOFOLLOW
.Event.xml:
events.xml is located at
app/code/{Vendor}/{Modulename}/etc/frontend/
code should be like thatObserver class
NoindexfollowOnProduct.php is located at
app/code/{Vendor}/{Modulename}/Observer
and the code should be like thatAlso, this module should have:
app/code/{Vendor}/{Modulename}/etc/module.xml
.app/code/{Vendor}/{Modulename}/composer.json
app/code/{Vendor}/{Modulename}/registration.json
.After adding the event you should flush the cache.