Magento Meta Tags and Titles
This is an update to all the magento meta data posts we’ve had so far. This will allow you to configure meta data and custom page titles.
What the following script will do is:
- Check for the default meta info and remove tags
- Ability to add meta info to pages individually
- Keep old meta data if its not in the list of pages and has not got the default meta info
This technique is especially useful as it allows you to add meta information to pages where you may not be able to do so in the code or in the CMS. Pages such as the checkout and the contact pages. I have included these two into the example below.
What you need to do is edit your head.phtml file and paste the following above everything.
<?php
$page = $_SERVER['REQUEST_URI'];
//add your pages into this array
$pagearray = array("shop/contacts","shop/checkout/cart");
foreach($pagearray as $pages){
$test = strpos($page,$pages);
if($test !== false){
$pageres = $pages;
}
}
if($pageres){
switch($pageres):
// case 1 here
case "shop/contacts":
$title = "Contact";
$keywords = "contact, me, at, my, store";
$description = "Contact me at my store.";
break;
// case 2 here
case "shop/checkout/cart":
$title = "Checkout - My Test Store";
$keywords = "Checkout, Buy, My, Things";
$description = "Buy my things at my test store.";
break;
endswitch;
} else {
// if not in the array do the normal
$keywords = $this->getKeywords();
$description = $this->getDescription();
$title = $this->getTitle();
}
//check for default - if default remove the meta info
if($keywords == "default"){
$keyw = false;
} else {
$keyw = true;
}
if($description == "default"){
$desc = false;
} else {
$desc = true;
}
?>
The above is quite simple and will let you add pages to an array and then add them to the case statement in order to specify the meta information.
Next you will simply need to add some conditional braces around your usual meta tags and change what is echo’d.
<title><?php echo $title ?></title>
<meta http-equiv="Content-Type" content="<?php echo $this->getContentType() ?>" />
<?php if($desc){ ?>
<meta name="description" content="<?php echo $description; ?>" />
<?php } ?>
<?php if($keyw){ ?>
<meta name="keywords" content="<?php echo $keywords; ?>" />
<?php } ?>
Again it’s these simply little tricks that can lead to better Search Engine rankings – the less duplicate data – the better!
Thanks for visiting the magento blog at ecommerce website design home of the magento fox!


Thank you!
I have been looking for that for quite some time. Helped a lot just was struggling a bit with the relative links in magento but managed to get that working.
Thanks again,
Adam