Get the meta description and page title on any pag

2019-03-03 19:12发布

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条回答
别忘想泡老子
2楼-- · 2019-03-03 19:40

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()
查看更多
登录 后发表回答