Editing meta tags for core pages in Magento

It’s easy enough to edit the default meta tags, or for CMS pages, product pages and category pages. But it’s not immediately apparent how to edit default meta tags in Magento, although from an SEO perspective it’s frequently useful to be able to do so.

Fortunately, there’s a nice easy way to do this, through the layout files.

Step By Step


First of all, figure out which layout file controls the page in question (this is normally pretty easy to do – anything in the customer area is controlled by the customer.xml layout file, anything in the checkout area is controlled by the checkout.xml layout file, and so on).

Find the layout file in your theme folder’s layout folder – if it’s not there, then you’re using the base layout, so be sure to copy that across from app/design/frontend/base/default/layout/ to your layout folder before making any changes, to ensure that those changes survive any future upgrades.

Then find the relevant bit of the layout file which deals with the page in question – again, this is pretty easy to do, as it’ll have start and end tags which correspond to the page, so the forgot password section in the customer layout, for example, will have the following start and end tags :

<customer_account_forgotpassword translate="label>
...
</customer_account_forgotpassword>

There may, or may not, be a reference in the relevant section dealing with the head section of the page. If there is, it’ll look something like this :

<reference name="head">
...
</reference>

To edit the page title, keywords meta tag and description meta tag, one simply needs to add into that section one or more of the following :

<action method="setTitle" translate="title" module="customer""><title>The title you want (will apply to all pages in the customer management section unless otherwise over-riden)</title></action>
<action method="setKeywords"><title>the, keywords, you, want, to, add, in</title></action>
<action method="setDescription"><title>The description you want to show</title></action>

And that’s it – flush the cache, restart Apache (if you’re using APC) and restart Varnish (if you’re using Varnish) and your changes should show up immediately.