SEO with Magento Layout XML

Over the years I have collected several useful layout XML code snippets that you can e.g. insert into individual Magento CMS pages or into your layout xml code in the local.xml file. This offers several changes to improve your search engine optimization (SEO) for your Magento store.

Set NOINDEX via Layout XML

If you want to exclude certain pages from search robots like the Google crawler, you can add a header <meta name="robots" content="NOINDEX,NOFOLLOW" /> to the page. To achieve this here comes a handy layout XML that you can simply paste into your Magento CMS pages in the "Design Updates" section and the header will automatically be added.

<reference name="head">
    <action method="setRobots"><value>NOINDEX,NOFOLLOW</value></action>

Canonicals via Layout XML

In case you have e.g. one CMS page that is available under different urls you should take care of so-called canonicals. More details can be found in my blog post about avoiding duplicate content in Magento.

For this I have build a handy helper method for use within Magento Layout XML. This helper method sets the current url for the given store as the canonical:

<reference name="head">
    <action method="addCanonicalLinkRel">

Increase Cache Lifetime

Also relevant for search optimization is the performance of your Magento store. While I have already written more details about that performance topic in a separate blog post this short Layout XML snippet allows to set the cache lifetime of parts the current page individually:

<reference name="footer">
    <action method="setCacheLifetime"><lifetime>86400</lifetime></action>

More details about disabling the cache can also be found on Fabrizios old blog post.