0

How to change meta data(robots meta tag) from controller in Magento ? Is there a way to access head block from controller and append new value in it ?

1

Yes definitely you can use the following code in your controller action method:

$this->getLayout()->getBlock('head')->setTitle($this->__('My Custom Meta Title'));

You just need to ensure that this code is called after $this->loadLayout(); and before $this->renderLayout();

Extra methods:

  • setDescription to set the meta description
  • setKeywords to set the meta keywords
3
  • can i use this anywhere in magento? – miso 911 Feb 11 '17 at 9:31
  • @miso911 no only in controllers – Raphael at Digital Pianism Feb 11 '17 at 14:50
  • setDescription is working but when i add this $this->getLayout()->getBlock('head')->addItem('link_rel', $prevUrl, 'rel="prev"'); on first page is working well but on 2, 3 , 4 .. is not working. – miso 911 Feb 12 '17 at 17:16

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.