I have 2 custom attributes I\'d like to add to the tags on product pages. They are \'brand\' and \'subtitle\'.
My page title would end up
Here is the simplest and best way to override META logics for product page in magento
copy /app/code/core/Mage/Catalog/Block/Product/View.php to /app/code/local/Mage/Catalog/Block/Product
and override function _prepareLayout(), my example goes bellow
protected function _prepareLayout()
{
$this->getLayout()->createBlock('catalog/breadcrumbs');
$headBlock = $this->getLayout()->getBlock('head');
if ($headBlock) {
$product = $this->getProduct();
$title = $product->getMetaTitle();
// SEO values start
$categoryCollection = $product->getCategoryCollection();
foreach ($categoryCollection as $k) {
$topCategory = Mage::getModel('catalog/category')->load($k->getId());
break;
}
$brand = $product->getResource()->getAttribute('brand')->getFrontend()->getValue($product);
$shortDescription = $product->getShortDescription();
$suffix = Mage::getStoreConfig('design/head/title_suffix');
// SEO values end
if (!$title) {
$title = $product->getName() .' '.$brand. ' - '. $topCategory->getName() . $suffix;
}
$headBlock->setTitle($title);
$keyword = $product->getMetaKeyword();
$currentCategory = Mage::registry('current_category');
if ($keyword) {
$headBlock->setKeywords($keyword);
} elseif($currentCategory) {
$headBlock->setKeywords($product->getName());
}
$description = $product->getMetaDescription();
if (!$description) {
$description = $brand. ' '. $topCategory->getName() .'. '. $shortDescription;
}
$headBlock->setDescription( ($description) );
// var_dump($title);
// var_dump($description);
if ($this->helper('catalog/product')->canUseCanonicalTag()) {
$params = array('_ignore_category'=>true);
$headBlock->addLinkRel('canonical', $product->getUrlModel()->getUrl($product, $params));
}
}
return parent::_prepareLayout();
}