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.
What is URL Rewrite? URL Rewrite is one of the most awesome tools by Magento 2 that allows you to edit any URL linking to a product, category or CMS page. After enabling the rewrite, the visitors who access the old link will be navigated to the new address to get more information.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With