:::: MENU ::::

Magento 2 set meta tag

Magento 2 set meta tag

Every Magento project requires a certain level of customization. This may involve adding a new element or overriding an existing one. Today, we’ll talk about how to set Meta tag like Meta title Meta Keyword and Meta description programmatically in Magento 2.For any suggestions & question, please feel free to drop a comment.



$this->pageConfig->getTitle()->set(__('First Hello World Module')); //setting the page title
$this->pageConfig->setDescription('test description'); // set meta description
$this->pageConfig->setKeywords('test keywords'); // set meta keyword




namespace QaisarSatti\HelloWorld\Controller\Index;

use Magento\Framework\View\Result\PageFactory;

class Index extends Action {

protected $_resultPage;

public function __construct(
PageFactory $resultPage) {
$this->_resultPage = $resultPage;
public function execute() {
$result= $this->_resultPage->create();
$result->getConfig()->getTitle()->set("Meta Title"); //setting the page
$result->getConfig()->setDescription("Description"); // set meta description
$result->getConfig()->setKeywords("Key Words"); // set meta keyword

return $result;
Author: Qaisar Satti
Category: Magento 2
Last Modified: July 12, 2018


  • Reply Johny Jackson |

    Hello mates, good article and fastidious urging commented here, I am truly enjoying by these.

  • Reply Johny Jackson |

    I do not even know how I ended up here, but I thought this post was great.

    I don’t know who you are but certainly you’re going to a famous blogger
    if you are not already 😉 Cheers!

  • Reply thila |

    I want to add meta datas dynamically in product category page in programmatically in magento 2….Am new in magento thanks in advance

  • Reply Raja Usman |

    This post is great, I was stuck but after found this article i solved my problem.

So, what do you think ?