Magento – Get the meta description and page title of any page

magento-1.9meta-tagsphp-5.4

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?

Best Answer

Try this code:

 <?php
    $this->getLayout()->getBlock('head')->getTitle();
    $this->getLayout()->getBlock('head')->getDescription();

    ?>