Editing Magento’s Top Links (The Better Way)
You might need to read the post about using a local.xml file before this post makes much sense.
We offer all our clients a completely customized design from scratch, which means changing anything – including those annoying defaulted top links. This post will show you how to edit your top links (without editing core layout files which may change when you update Magento) by utilizing a local.xml file. You can even add your own custom links without touching any template files! [NOTE: This specific example assumes you are using the blank theme. Layout handles may differ from theme to theme.]
ADDITION: Check out the blog post about editing Magento’s footer links
In local.xml:
<?xml version="1.0"?> <layout version="0.1.0"> <default> <reference name="root"> <reference name="top.links"> <!-- Add custom links. Pretty self-explanatory. Dig into app/code/core/Mage/Page/Block/Template/Links.php for more info --> <action method="addLink" translate="label title"> <label>About Us</label> <url>about</url> <!-- can use full url also --> <title>About Us</title> <prepare>true</prepare> <!-- set true if adding base url param --> <urlParams helper="core/url/getHomeUrl"/> <!-- base url - thanks @Russ! --> <!-- there are a few param you can send to do different things in <urlParams> dig into app/code/core/Mage/Core/Model/Url.php, around line 803 --> <!-- below adds #add-fragment to the end of your url --> <!-- <urlParams><_fragment>add-fragment</_fragment></urlParams> --> <!-- below adds ?add-query to the end of your url --> <!-- <urlParams><_query>add-fragment</_query></urlParams> --> <!-- below gives you a new session id (i think...)--> <!-- <urlParams><_nosid>true</_nosid></urlParams> --> <!-- below replaces double quotes, single quotes, greater than, and less than signs to their respective url escaped replacements (%22, %27, %3E, %3C) --> <!-- <urlParams><_escape>i'm-a-blog-url</_escape></urlParams> --> <position>1</position> <liParams/> <aParams>class="top-link-about-us"</aParams> <beforeText></beforeText> <afterText></afterText> </action> <!-- Removes 'My Account' link - Default position: 10 --> <action method="removeLinkByUrl"><url helper="customer/getAccountUrl"/></action> <!-- Removes 'Wishlist' link - Default position: 20 --> <!-- for Magento 1.3.x --> <action method="removeLinkByUrl"><url helper="wishlist/"/></action> <!-- for Magento 1.4.x --> <remove name="wishlist_link"/> <!-- Removes 'My Cart' AND 'Checkout' links Default position: 40 and 50 respectively --> <remove name="checkout_cart_link"/> <!-- To re-add 'My Cart' or 'Checkout' after removing both --> <block type="checkout/links" name="checkout_cart_link_custom"> <action method="addCartLink"></action> <action method="addCheckoutLink"></action> </block> </reference> </reference> </default> <customer_logged_out> <!-- Removes 'Log In' link - Default position: 60 --> <reference name="top.links"> <action method="removeLinkByUrl"><url helper="customer/getLoginUrl"/></action> </reference> </customer_logged_out> <customer_logged_in> <!-- Removes 'Log Out' link - Default position: 60 --> <reference name="top.links"> <action method="removeLinkByUrl"><url helper="customer/getLogoutUrl"/></action> </reference> </customer_logged_in> </layout> |
If you absolutely cannot find a way to customize your top links using these methods, you can edit the /template/page/template/links.phtml
This entry was posted on Wednesday, February 24th, 2010 at 2:23 pm and is filed under Development, Magento Development. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
February 25th, 2010 at 5:53 pm
thanks! BTW, there’s a missing close bracket on
February 25th, 2010 at 6:20 pm
Sadly, this code chokes on wishlist for me under 1.4.0.0. Any ideas?
a:5:{i:0;s:278:”Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, ‘Mage_Wishlist_Helper_Data::’ was given in \app\code\core\Mage\Core\Model\Layout.php on line 326″;i:1;s:1934:”#0 \app\code\core\Mage\Core\Model\Layout.php(326): mageCoreErrorHandler(2, ‘call_user_func_…’, ‘C:\web\root\…’, 326, Array)
February 26th, 2010 at 8:37 am
Thanks bluescrubbie,
It looks like in 1.4 they changed the wishlist.xml – just replace:
<action method="removeLinkByUrl"><url helper="wishlist/"/></action>with:
<remove name="wishlist_link"/>Because of the “remove” global effect, if you want to re-add the wishlist link somewhere else, you need to create a custom block. I just copy it from wishlist.xml, change the name attribute of the block, and place it in my local.xml file.
March 7th, 2010 at 6:07 am
Thank you, this is extremely helpfull
March 18th, 2010 at 4:33 am
Thanks for the info on removing links; I’m trying to add a link to a cms page and to the homepage using the method above, but the links generated are not parsed in any way eg. home just passes “home” as the complete anchor href element href=”home” which is incorrect.
The same is true for my CMS page, which breaks these links from pages where the base url is wrong, like the customer account page; the links suddenly become href=”customer/account/home” and “customer/account/customer-service” for example.
Any thoughts on how to make Magento parse the page names and insert fully qualified URI’s as it does for ‘helper’ links like the customer login & basket links?
March 22nd, 2010 at 9:52 am
@Russ – thanks for that question.
I dug into the app/code/core/Mage/Page/Block/Template/Links.php file. You can use the full url in your ‘url’ tag or add a param to the addLink method. The latter is shown here – in your local.xml:
March 26th, 2010 at 2:18 am
I am trying to do the same thing, however I cant seem to get it to work atall without crashing. I want to add 2 links to the top link of the site that direct to a CMS page. What files do I modify?
thanks in advance
March 26th, 2010 at 12:15 pm
Wow both this is awesome! I have been fighting magento for going on a year. hopefully with help from this we will be able to streamline our magento development
March 29th, 2010 at 4:28 am
Thanks for the great manual!
My problem is with multilanguage shops.
Can you say me how to translate, for example, About us to “&Uml;ber uns”.
April 19th, 2010 at 9:33 am
Thanks for this, very helpful!
April 27th, 2010 at 12:25 pm
Hi
Using 1.4, the customer logged on/out code doesn’t work.
Ay ideas gratefully received.
Thanks
Jerry
April 29th, 2010 at 10:24 am
Thanks kkirchner,
I didn’t want to hard-code links as we run about a dozen sites, But I did a little digging myself and came up with this code for local.xml which uses a url helper to generate the correct URL for the homepage of the current site.
April 30th, 2010 at 7:53 am
Wow, Russ! That looks great. I’m definitely going to check this out – that could be super helpful!
May 5th, 2010 at 1:19 pm
@Jerry – I tested the logged in and logged out on 1.4 with the blank theme and it worked for me… double check and make sure they’re after the </default> tag.
May 24th, 2010 at 9:17 pm
There is an error in the local.xml posted. The beforeText tag was not properly closed.
Kindly change to:
May 24th, 2010 at 9:53 pm
Also, kindly change the local.xml posted above to remove the log out url when the customer is logged out and to remove the log in url when the customer is logged in.
May 25th, 2010 at 7:58 am
@James Wyson – Can you wrap your code examples in pre tags? See the example code above the comment box for details.
May 26th, 2010 at 8:56 am
@James Wyson – Thank you for catching that error. I’ve properly closed the beforeText tag.
Also, the log in link only shows when the user is logged out. And conversely, the log out link only shows when the user is logged in. So you have to wrap the remove login link in the customer_logged_out tag and the remove logout link in the customer_logged_in tag. The code shown above for local.xml is correct.
May 27th, 2010 at 10:10 am
Very much apprecaited – very helpful!
June 9th, 2010 at 8:18 am
Sorry for the amount of spam, the code and pre tags didn’t work for me
Hi, I’m trying to edit the customer_account_navigation block to remove the My Tags and My Product Reviews links but I can’t make it. This is what I’ve tried so far in local.xml:
<customer_account>
<reference name="customer_account_navigation">
<remove name="tags"/>
</reference>
</customer_account>
Also,
<action method="removeItem"><name>tags</name><path>tag/customer/</path><label>My Tags</label></action>
<action method="unsetChild"><name>tags</name></action>
<action method="removeLinkByUrl" module="tag"><url>http://www.localhost.com/magento/index.php/tag/customer/</url></action>
<action method="removeLinkByPath" module="tag"><name>tags</name><path>tag/customer/</path></action>
Do you have any ideas? Thanks for the help!
June 11th, 2010 at 7:23 am
@Vier,
Both Tags and Reviews are Magento core modules which you can disable in the admin. Once you disable them, the links will no longer show up on your customer account list of links.
Under System > Configuration > Advanced (bottom of left sidebar) > Disable Module Output. Select Disabled for Mage_Review and Mage_Tag.
June 11th, 2010 at 8:14 am
@kkirchner,
I knew abou the easy way, but I was just wondering if it could be done the other way round
Thanks for your time!
June 11th, 2010 at 8:42 am
Another option – you can copy the removeLinkByUrl method in app/code/core/Mage/Page/Block/Template/Links.php and paste it in a custom module that extends the Mage_Customer_Block_Account_Navigation class in app/code/core/Mage/Customer/Block/Account/Navigation.php. If you’re going to go that far, you might as well add a custom helper to get the tag and review path with your baseUrl. Check out this comment.
June 16th, 2010 at 3:58 pm
New to Magento development here. Is there an easy way to edit the text of My WishList and My Account this way? I want to edit My Wishlist to simply say “Wishlist”. I would like to edit My Account to say “Sign In” (only when a user isn’t currently signed in).
June 16th, 2010 at 4:27 pm
@Brandon – The simplest solution for making changes like that is to use the Translate Inline tool. You can turn on this tool on the System > Configuration > Developer page.
June 17th, 2010 at 7:03 am
@ehansen,
Thanks for the tip. I’ll give that a shot and see how it goes.
June 23rd, 2010 at 9:38 am
I wanna know where i should place the code showing above …Thanks for help
June 23rd, 2010 at 10:08 am
@Yasmine – The code goes in a local.xml file. To learn about where to put the local.xml file, take a look at our blog post here.
Thanks!
June 29th, 2010 at 11:28 am
Hi,
pay attention when you specify a “false” value: leave the tag empty (ie: ) or use 0 as false (ie: 0) otherwise you won’t get what you expect.
Thank you for your help.
Sincerely, Alessandro
June 29th, 2010 at 11:29 am
Hi,
pay attention when you specify a “false” value: leave the tag empty (ie: <prepare/>) or use 0 as false (ie: <prepare>0</prepare>) otherwise you won’t get what you expect.
Thank you for your help.
Sincerely, Alessandro
August 12th, 2010 at 10:00 am
Was an expression of thanks really useful.
August 30th, 2010 at 7:12 am
Thanks, couldn’t quite get those darn links removed with the other solutions. This one finally seemed to work.
September 10th, 2010 at 1:04 am
HI I WANT TO remove totally menu and add new html as topnew.phtml i have done like this in local.xml
its removing top.phtml but i cant add topnew.pthml Please help me…
Waiting for reply
September 10th, 2010 at 1:05 am
HI I WANT TO remove totally menu and add new html as topnew.phtml i have done like this in local.xml
its removing top.phtml but i cant add topnew.pthml Please help me…Can anyone??
Waiting for reply
November 9th, 2010 at 5:38 am
Bravo! The top links were doing my head in… it’s nice to have them in one place! Thanks for the info.
December 26th, 2010 at 9:36 am
Thanks, I’ve been struggling with this for a while! Top menu links now edited!
January 19th, 2011 at 1:35 pm
Thanks for these great alternatives!!
I have a new question for you. I’m using a custom theme and a one column format throughout the entire site. My problem is that when users wish to click on “Add to Compare” for several products, the corresponding link to “Compare Products” is not available anywhere. I wanted that link to automatically be available in the top links discussed above. In the 2 or 3 column format, the “Compare Products” list and link is in the sidebar for immediate access.
Any thoughts on this dilemma???
Thanks again!!
Jef
January 20th, 2011 at 9:43 am
@Jef – Very interesting question. I dug in to catalog.xml and catalog/product/compare/sidebar.phtml to see what I could find.
The button that opens the comparing pop-up box uses a php method to dynamically create the pop-up box. So you can probably use your own phtml file for it.
In local.xml:
Now create the
comparelink.phtmlfile and modify the code fromcatalog/product/compare/sidebar.phtml:I’ve not tested this but it should work in theory… good luck!
January 20th, 2011 at 12:03 pm
Whoa! Very deep! I’ll give this implementation a try and let you know how it goes. Thank you very much for the response and idea!
Jef
January 24th, 2011 at 9:45 am
Such a good system is the old Magento, but for the fact that there is no decent way to manage those frickin menus! menu items should be pulled from the database as proper menu items, that are linked to “menus” which are also stored in the database, then, only once that is working OK should they add in the ability to override (via XML) full menus, ir single menu items. I think that is a good balance between “developer” friendly, and “commercial self preservation”. I.e. only savvy developers can work it out, apart from the people that make money at Magento – I believe this is their business model in the big picture, I dont blame them either
February 4th, 2011 at 4:55 am
Great reading!
Makes magento to customize way simpler! I’m trying to add front page to my navigation, but it just dont work. I did managed to add it to top.links. Here is my code, magento 1.4.2.0
<PRE>
Home
/
Home
true
0
class=”top-link-about-us”
</PRE>
February 4th, 2011 at 4:56 am
hm,,, didn’t pasted it ok ?
Home
/
Home
true
0
class="top-link-about-us"
February 4th, 2011 at 5:05 am
Home
/
Home
true
0
class=”top-link-about-us”
February 6th, 2011 at 1:13 am
great , it help me ,too. TKS. ( in ver.1.4 )
March 2nd, 2011 at 12:16 pm
Heya kkircher,
(firstly, apologies for the miss-post above, please delete!)
Is there any additional magic to making this work with the category links instead of top.links ?
I am trying the below in catalog.xml to start with prior to trying to moving it into local once its working (local I assume has an unset issue as it causes an exception!) ?
<reference name=”top.menu”>
<block type=”catalog/navigation” name=”catalog.topnav” template=”catalog/navigation/top.phtml”>
<action method=”addLink” translate=”label title”>
<label>Home Page</label>
<url helper=”core/url/getHomeUrl”/>
<title>Home Page</title>
<prepare/>
<urlParams/>
<position>1</position>
</block>
</action>
</block>
</reference>
I assumed the above would work (1.5.0.1, blank theme), but in effect nothing gets output. Suggestions welcome!
March 9th, 2011 at 11:07 pm
running 1.4.2.0 and the wish code still breaks the site. any ideas? what am i doing wrong?
Also trying to hard code adding a navigation link at top.phml. when I edited the code the main-container area is broke. Any help you can give is greatly appreciated.
Thanks
March 30th, 2011 at 1:56 pm
This an excellent tutorial. Thank you. I am trying to use this to add a link to the top.links that points to another domain. So far I have had no luck. No matter what I do, Magento just appends the link to the end of my base url.
Any help would be greatly appreciated.
March 30th, 2011 at 2:46 pm
@Jameson Proctor
I figured it out <prepare>true</prepare> needs to be set to <prepare /> not <prepare>false</prepare>. For some reason, prepare to false is no different than setting it to true.
April 8th, 2011 at 3:37 pm
Wishlist removal code does not work anymore with 1.5, I just deactivate it in control panel ´cause I won´t need it.
April 14th, 2011 at 1:43 pm
Andy, I’m running 1.4.2.0 as well and this method (that I found another forum) for knocking out the wishlist worked for me:
Comment out the following from frontend/default/yourtheme/layout/wishlist.xml. Just make sure your cache is disabled and such.
<!–
–>
Really wish there was a less-complicated way to do all this…
April 14th, 2011 at 1:45 pm
Er, the code didn’t show up, how do I post code
June 21st, 2011 at 8:26 am
HowTo Remove WishlistLink:
Workaround: http://stackoverflow.com/questions/4423631/magento-removing-wishlist-link-in-1-4-2
blank-link.phtml
HowTo Set CSS ID in ul tag:
namemain_nav
....
June 21st, 2011 at 8:29 am
er code messed up…
HowTo Remove WishlistLink:
Workaround: http://stackoverflow.com/questions/4423631/magento-removing-wishlist-link-in-1-4-2
HowTo Set CSS ID in ul tag:
<code>
namemain_nav
….
</code>
June 21st, 2011 at 8:32 am
third try:
er code messed up…
HowTo Remove WishlistLink:
Workaround: http://stackoverflow.com/questions/4423631/magento-removing-wishlist-link-in-1-4-2
HowTo Set CSS ID in ul tag:
<reference name="top.links">
<action method="setData"><key>name</key><value>main_nav</value></action>
....
</reference>
July 19th, 2011 at 4:16 am
thanks for the information. It is actually very helpful to the ones who are using magento for their online stores.
January 8th, 2012 at 3:54 am
magento commerce templates…
[...]Editing Magento’s Top Links (The Better Way) » Classy Llama Studios – Specializing in Magento eCommerce, Magento Development, and Magento Design[...]…
January 14th, 2012 at 11:53 am
siteranger…
[...]Editing Magento’s Top Links (The Better Way) » Classy Llama Studios – Specializing in Magento eCommerce, Magento Development, and Magento Design[...]…
January 16th, 2012 at 1:17 pm
Link Lizard…
[...]Editing Magento’s Top Links (The Better Way) » Classy Llama Studios – Specializing in Magento eCommerce, Magento Development, and Magento Design[...]…
January 18th, 2012 at 8:16 pm
rippe lifestyle institute…
[...]Editing Magento’s Top Links (The Better Way) » Classy Llama Studios – Specializing in Magento eCommerce, Magento Development, and Magento Design[...]…
January 24th, 2012 at 9:56 pm
product reviews…
[...]Editing Magento’s Top Links (The Better Way) » Classy Llama Studios – Specializing in Magento eCommerce, Magento Development, and Magento Design[...]…