addLinks to top.links in Magento

We’re always creating custom┬ámagento implementations for our clients and that typically starts with a local.xml file. One of our┬ámore common tasks revolves around adding and/or removing links from the “top.links” portion of the header.

Below you can see an example of a best practice when it comes to adding a new link to the top.links within Magento. The snippet does utilize some lesser known child nodes

The trick here is that the “urlParams” node in our XML below is referencing a helper class to build out the link that will eventually show up in top.links instead of hardcoding a “/” at the beginning of our “url” node.

<layout version="0.1.0">
        <reference name="top.links">
		<action method="addLink" translate="label title">
		        <label>Free Shipping &amp; Returns</label>
		        <title>Free Shipping And Returns</title>
		        <urlParams helper="core/url/getHomeUrl"/>

Since switching over to the structure above it’s helped our team alleviate QA issues that previously came up when migrating from one server to another and one server possibly used a different base path that included a subfolder.

Example URL

Aaron Ware

For nearly 20 years Aaron Ware has worked with leading brands, start-ups and everyone in between to develop innovative, highly interactive, feature-rich websites, and online apps.

| @aaronware