php Archives -

Blog Archives

Magento, HREF Lang plugin

Posted on October 3, 2014 by

One of our clients approached us to build a way that they could manage hreflangs on their Magento stores where they were looking to have multiple language versions of the site with different pages on each site. I looked at a few options online and there were some that worked provided the sites would be identical in terms of content but none that would enable control of where the links would go if there wasn’t an alternative url.

… so I built a plugin that enables our client to upload their urls in a csv with the base site in the first column and then they can add as many columns after that to upload the urls for the other language sites. The plugin then retrieves any alternate urls for any other site from the data and adds them to the <head> section of the website.

If this is a solution you think you would require for your multi language Magento, then please don’t hesitate to contact us at info@web-feet.co.uk.

Magento HREF, multi-language


Magento SEO PHP Product, Category Descriptions and defaults

Posted on November 1, 2013 by

Struggling to generate meta keywords or descriptions automatically on your Magento category and product pages? This blog should help you through the code needed.

Magento is great for many things and from an SEO development point of view it is pretty good but not perfect. Our SEO maestro wanted me to implement some code that if there was a product description it would use that to populate the meta description. After doing some searching, I came across this blog post. This gave me a good starting point but I also needed to do this for category pages as well and our set up required that I looked into a couple of other things. The main issue was that we had populated the default meta description and keywords already so the code needed to check if the keywords for the product where not empty and not equal to the default before deciding what to do.

The code I ended up with is placed in the page/html/head.phml of the theme we are using:

<?php
$desc = strip_tags(trim($this->getDescription()));
$kw = trim($this->getKeywords());
$title = strip_tags(trim($this->getTitel()));

 if (Mage::registry('current_product')) {
   $desc = $this->getTitle(). ' '. strip_tags(str_replace("<br />",", ",substr(Mage::registry('current_product')->getDescription(), 0, strpos(Mage::registry('current_product')->getDescription(), '.')+1)));

   $desc = substr($desc, 0, 150);

   if($title = Mage::getStoreConfig('design/head/default_title') || $title == Mage::registry('current_product')->getDescription())
   {
 
     if(strtolower(substr($desc, 0, strlen($title))) !== strtolower($title))
     {
       $title = Mage::registry('current_product')->getName().' '.strip_tags($desc);
     }
   }
 
   if(empty($kw) || $kw == Mage::getStoreConfig('design/head/default_keywords'))
   {
     $kw = $title.','.$kw;
   }
 }
 
 if (Mage::registry('current_category')) 
 {
   if(empty($desc) || $desc == Mage::getStoreConfig('design/head/default_description'))
   {
      $desc = $this->getTitle(). ' '. strip_tags(str_replace("<br />",", ",substr(Mage::registry('current_category')->getDescription(), 0, strpos(Mage::registry('current_category')->getDescription(), '.')+1)));
      $desc = substr($desc, 0, 150);
   }
   if(empty($kw) || $kw == Mage::getStoreConfig('design/head/default_keywords'))
   {
      $kw = $title.','.$kw;
   }
 }

// ... do what is necessary <title..., <meta name="description... etc
?>

As you can see from the code ; there are quite a few checks and replacements going on to ensure html is not passed through to the head items and also to ensure there isn’t too much duplication of the product name in the description.


Some of our happy customers

logo ahmad
logo poingdestres
logog swiss
logo ibhs 1
ww
logo sgc
logo nationwide
logo undersea
logo roughton
logo stcross
logo pulse
logo mm
logo jfl
logo heritage 1
logo firesafe
logo electrofreeze
logo clickmetal
logo baguetti
bpc
logo ccc 1
log arokah
logo labs
logo paragon
logo trant
logo nahh
logo edge
logo romsey
ace1
ace2
spaceway logo
logo bookharbour
logo chartco
logo cranbourne
logo magister
logo mgmetals
logo westway
logo ocean
logo testvalley
logo brittania
logo faac
recref
logo gss