Add Noindex Meta Tag To Particular View

Not all pages should have a "index,follow" as robots meta tag, so I wanted to replace it in some views like this:




Yii::app()->clientScript->registerMetaTag('noindex,noarchive','robots');



Could please anybody help me?

Have not used this, but you might need to remove the "index,follow" from the main layout, add the registerMetagTag() for the "index,follow". Then maybe when you register the "noindex,…" it would over-write the first one.

Edit Just reread the api. that won’t work. I think you will need a php switch in layout/main to place the tag you want as needed. Maybe a controller level public variable that you could check in the layout.

Thanks for your reply. I tried using the above code. The plugin shows the page is not getting indexed but the layout file has both meta tags with index and noindex. Will that cause any problem ?

Don’t know. As the edit shows, the Yii api indicates that the double porting is to be expected.