PHP Magento Tips

Powered by Blogger.

How to Get Magento Meta keywords Dynamically on Product Page?

Rate this posting:

In order to generate Meta Keywords Dynamically for Product Page, We have to create Event in Magento.

Step 1:

In app/etc/modules/Mycompany_Getkeywords.xml add Below Code:

<?xml version="1.0"?>
              <Mage_Catalog />

Step 2:

In app/code/local/Mycompany/Getkeywords/etc/config.xml add Below Code:

<?xml version="1.0" encoding="UTF-8"?>
            <catalog_controller_product_view><!-- event observer -->

Step 3:

In app/code/local/Mycompany/Getkeywords/Model/Observer.php add Below Code:

class Mycompany_Getkeywords_Model_Observer {
public function productView(Varien_Event_Observer $observer)
        $product = Mage::registry('current_product');
        if ($product && $product->getId()) {
            // Add Product keywords
            $keywords = $product->getMetaKeyword();
            // Add category name
            $categoryIds = $product->getCategoryIds();
            foreach ($categoryIds as $category_id) {
                $_cat = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($category_id);
                $catinfo = $catinfo.", ".$_cat->getName();
                $catnames = ltrim($catinfo,", ");
            // Add product name
            $productname = $product->getName();

            // Generate dynamic meta keyword tag
            if (!empty($keywords)) {
                $dynamickeywords = $keywords.", ".$catnames.", ".$productname;
            } else {
                $dynamickeywords = $catnames.", ".$productname;

Additionally, you can set Meta Title with setMetaTitle and Meta Description with setMetaDescription.
Tag : Magento
0 Comments On "How to Get Magento Meta keywords Dynamically on Product Page?"

Back To Top