Get the meta description and page title on any page in Magento

喜夏-厌秋 提交于 2019-12-04 06:19:30

问题


How can I get the meta description and page title of any page in Magento (product page, category page, CMS page and any other page). This is for Magento 1.9.

I have tried something along the lines of:

if( Mage::registry('current_product') ){  // product page
    $product = Mage::registry('current_product');
    $title = $product->getMetaTitle();
    $descr = $product->getDescription();
}elseif( Mage::registry('current_category') ){  // category page
    $category = Mage::registry('current_category');
    $title = $category->getTitle();
    $descr = $category->getDescription();
}else{  // CMS / any other page
    $title = $this->getTitle();
    $descr = $this->getDescription();
}

But this isnt working in every case. Can anyone help?


回答1:


To get the page title on any page, use:

$title = $this->getLayout()->getBlock('head')->getTitle()

To get the meta description on any page, use:

$descr = $this->getLayout()->getBlock('head')->getDescription()


来源:https://stackoverflow.com/questions/35481325/get-the-meta-description-and-page-title-on-any-page-in-magento

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!