Magento – Magento2 : Not showing Meta title & description on category page

magento-2.2.5magento2meta-descriptionmeta-tagsmeta-title

I'm getting issues with website meta info. If I will set the default meta info then it will display the same info tag for all the pages.

But when I'm trying to set the meta info for a particular page then it will not display the Meta title & description.

I have set the Meta description & title for one category. In this case, the Meta description & title tag showing for the same category page.

Solution I applied to display both the tags for category pages:

I have created one observer & set the description for the current category. But when I tried to set the title then I got the below error.

Recoverable Error: Object of class Magento\Framework\View\Page\Title
could not be converted to string in
/var/www/html/htdocs/vendor/magento/framework/View/Page/Config/Renderer.php
on line 125

I used the below code to set the meta title & description.

$this->_pageConfig->setMetadata('title', 'some meta title');

$this->_pageConfig->setDescription($desc);

$this->_pageConfig->setKeywords($keyWrds);

Thanks for any help.

Best Answer

Use this code to set Metatitle,

$this->_pageConfig->getTitle()->set(__('Your Title'));

Related Topic