Meta Descriptions on Product Pages
Here at E-Commerce Website Design we always come up against certain flaws in the way in which Magento is coded. Most of these flaws we can solve, but some are just so deeply hard-coded into the framework that all we can do is hack away at it to produce the desired result.
Never has this been more the case than with the meta-description tag on the product pages. If you don’t know what I mean by this then here’s an example.
- You have a store that has hundreds of products – you let the client add all their products but the client knows nothing of SEO – plus its too time consuming to do it yourself so inevitably you leave the meta keywords and description fields empty.
In an earlier post (Magento SEO Meta data) we came up with a small hack to remove the meta descriptions on pages that have no meta data inserted – basically checking for the magento default value and removing the tags if we find it.
The old method:
<?php $checkd = "default";
$check2d = htmlspecialchars($this->getDescription());
if($check2d == $checkd){ } else { ?>
<meta name="description" content="<?php echo htmlspecialchars($this->getDescription()) ?>" />
<?php } ?>
- This is all well and good for category pages and CMS pages – but for product pages when the default meta description is called, magento instead uses the product description. This is very problematic for these reasons:
- Meta descriptions are too long
- If using a WYSIWYG editor – meta descriptions contain invalid HTML data.
Example:
So we thought that we would rectify these two issues for you all – so here it goes (the new method):
<?php $checkd = "default";
$check2d = htmlspecialchars($this->getDescription());
if($check2d == $checkd || strlen($check2d) > 250 || $check2d == "<p>&#160;</p>"){ } else { ?>
<meta name="description" content="<?php echo htmlspecialchars($this->getDescription()) ?>" />
<?php } ?>
The text in red is the change – what we’ve done is covered the length of the meta description (It’s good practice to keep it less than 250 characters anyway) and we have also covered the “empty error” which sometimes comes with WYSIWYG editors (<p>#160</p>). With this line of code in your head.phtml file, you should find less meta description errors in future crawls of your magento website.
Of course you don’t need to do this for the keywords tag.
Hopefully this will be something that they think to fix in the next release (although I haven’t seen it yet in 1.4.0.0).
Thanks for reading and I hope this helps you all!
<?php $checkd = "default";
$check2d = htmlspecialchars($this->getDescription());
if($check2d == $checkd || strlen($check2d) > 250 || $check2d == "<p>&#160;</p>"){ } else { ?>
<meta name="description" content="<?php echo htmlspecialchars($this->getDescription()) ?>" />
<?php } ?>
<?php
$check = "default";
$check2 = htmlspecialchars($this->getKeywords());
if($check2 == $check){ } else { ?>
<meta name="keywords" content="<?php echo htmlspecialchars($this->getKeywords()) ?>" />
<?php } ?>
