aserww106
aserww106

Reputation: 1341

magento - How to get product meta title?

I use following code to get the current product meta title, but it doesn't work.

$curr_prod = Mage::registry('current_product');
$meta_title = $curr_prod->getMetaTitle();
echo $meta_title;

I can get the correct $curr_prod object, but I don't know which method I should use to get the meta title of current product, anyone can help on this?

Thanks!

Upvotes: 2

Views: 5507

Answers (2)

Jim
Jim

Reputation: 70

$title = $product->getMetaTitle();
if ($title) {  
   $headBlock->setTitle($title.' - '. $product->getFinalPrice());
}

try the code it might work

Upvotes: 1

Ahmad Vaqas Khan
Ahmad Vaqas Khan

Reputation: 658

Set Meta information(Title, Keyword, Description) on Controller Action. Fetch meta information from product data and set the values for layout head block.

    $_product = Mage::getModel('catalog/product')->load($id);       

    if($_product){
        $title = $_product->getMetaTitle();
        $keyword = $_product->getMetaKeyword();
        $description = $_product->getMetaDescription();
    }

    $this->loadlayout();

    $title = $title!=""?$title:$this->getLayout()->getBlock('head')->getTitle();
    $keyword = $keyword!=""?$keyword:$this->getLayout()->getBlock('head')->getKeywords();
    $description = $description!=""?$description:$this->getLayout()->getBlock('head')->getDescription();

    $this->getLayout()->getBlock('head')->setTitle($title )
                                        ->setKeywords($keyword)
                                        ->setDescription($description);
    $this->renderlayout();

Upvotes: 0

Related Questions