How do I add links to Magento top.links that redirect to another domain?

I am able to add custom links to Magento’s top.links with the following code that I save in ../myCustomTheme/layout/local.xml

<reference name="root">
<reference name="top.links">
    <action method="addLink" translate="label title">
        <label>example</label>
        <url>example</url> 
        <title>example</title>
        <prepare>true</prepare> 
        <urlParams helper="core/url/getHomeUrl"/> 
        <position>100</position>
        <liParams/>
        <aParams>class="top-link-example"</aParams>
        <beforeText></beforeText>
        <afterText></afterText>
    </action>
</reference>
</reference>

The above code will create a link named example that points to http://myexampledomain.com/example. If I change this line of code

<url>example</url>

to

<url>http://myotherexampledomain.com</url>

I end up with a link named example that points to http://myexampledomain.com/http:/myotherexampledomain.com. I have tried setting the prepare parameter to false and adding various parameters to urlParams by looking at ../app/code/core/Mage/Core/Model/Url.php to no avail.

One thought on “How do I add links to Magento top.links that redirect to another domain?”

  1. So, I kept at this and I’ve got it working. Basically, prepare needs to be unset because, if it is set to “true” or “false”, it will append the URL to your site’s base URL. Here’s the corrected code:

    <reference name="root">
    <reference name="top.links">
        <action method="addLink" translate="label title">
            <label>example</label>
            <url>http://myotherexampledomain.com</url> 
            <title>example</title>
            <prepare/>
            <urlParams/> 
            <position>100</position>
            <liParams/>
            <aParams>class="top-link-example"</aParams>
            <beforeText></beforeText>
            <afterText></afterText>
        </action>
    </reference>
    </reference>
    

    I also removed helper=”core/url/getHomeUrl” from urlParams because the getHomeUrl function is not needed in this case. The above code creates a link named example that properly points to http://myotherexapmpledomain.com.

Leave a Reply

Your email address will not be published. Required fields are marked *