cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Coding in head.phtml (meta,title,description)

Re: Custom Coding in head.phtml (meta,title,description)

<?php
//increase the max execution time
@ini_set('max_execution_time', -1);
//memory_limit
@ini_set('memory_limit', -1);

error_reporting(E_ALL);
ini_set('display_errors', '1');

// // Start Despaly All Product Meta Title And Description
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();

$categories = Mage::getModel('catalog/category')
                         ->getCollection()
                         // magic is prepared here..
                         ->addAttributeToSelect('*')
                         // then the magic happens here:
                         ->addAttributeToFilter('level', array('eq'=>4))
                         ->load();
    if (count($categories) > 0):

        foreach($categories as $category):

            $catId = $category->getId();
            $category = Mage::getModel('catalog/category')->load($catId);

            //if($catId==1465):
                $CategoryName = $category->getName(); 
                $metaTitle = "Buy ".$CategoryName." Online India - RightGifting";
                $metaDescription = "Shop your favourite ".$CategoryName." for you or send a gifts purpose from RightGifting online store India. Offers available. 100% Fast & free shipping!";
                $category->setMetaTitle($metaTitle);
                $category->setMetaDescription($metaDescription);
                $category->save();

                $check = $category->getMetaTitle();
                echo "<pre>";
                print_r($check);
                echo "\n";
            //endif; 
            
        endforeach;
        
    endif;
?>

Re: Custom Coding in head.phtml (meta,title,description)

Please explain Where to add this code?

Re: Custom Coding in head.phtml (meta,title,description)

That's like the easiest task in Magento and I've got step by step instruction with video for you to help complete this task:

https://magefan.com/blog/how-to-add-custom-code-in-html-head

Re: Custom Coding in head.phtml (meta,title,description)

very weird that nobody understood the question :-(

one reply provides code based on Magento 1.9!

and all other provide links or whatever about adding custom code, like including script.

but the question is how to edit meta tags, like description, keywords, etc dynamically.

those one:

<meta name="title" content="xxxxxxxx"/>
<meta name="description" content="xxxxxxxxxxxx"/>
<meta name="keywords" content="xxx"/>

 

dynamically, so going to backend to override those values will not help neither...

 

in other words in which vendor/xx file are those values retrieved from DB so we can intercept and update dynamically? (in my case I need to concatenate with something stored in session object but it does not matter)

 

 

I hope it helps clarifying the request

thanks