Magento: The Clean Way To Remove “Contact Us” Footer Link
As a senior developer building your own theme based on the blank Magento template, you’re likely looking for ways to customize your footer without having access to the typical contacts.xml file where you can simply comment out the link. In this post, we’ll explore how to remove the “Contact Us” footer link using only your local.xml and layout remove methods.
Understanding The Issue
You’ve already discovered that Magento allows you to remove certain links from the footer using the removeLinkByUrl action in your local.xml file. This works perfectly for removing the advanced search link:
<default>
<reference name="footer_links">
<action method="removeLinkByUrl"><url helper="catalogsearch/getAdvancedSearchUrl"/></action>
</reference>
</default>
However, when you try to apply the same logic to remove the “Contact Us” link, it doesn’t work:
<default>
<reference name="footer_links">
<action method="removeLinkByUrl"><url>contacts</url></action>
</reference>
</default>
Even adding module="contacts" as an attribute in the action doesn’t solve the issue. So, what’s going wrong?
The Root Cause
The problem lies in how Magento handles the “Contact Us” link differently from other links like the Advanced Search. While most footer links are managed by the footer_links block, the “Contact Us” link is actually part of the static block that contains your store information.
By default, this static block (block_id="store_information" in your local.xml) includes a core template file called contacts.phtml. This file generates the “Contact Us” link using a helper function from the Core module (Mage_Core_Block_Template).
The Solution: Customizing Your Footer
To remove the “Contact Us” link, you’ll need to customize this static block and its associated template. Here’s how:
- Create a copy of the contacts.phtml file
Find your Magento installation directory and navigate to app/design/frontend/{package}/{theme}/template/page/html. Make a backup or delete the default contacts.phtml file, then create an exact copy named contacts_new.phtml.
- Modify the contacts_new.phtml file
Open this new file in your preferred code editor. You’ll see that it contains a PHP function called getContactUsUrl(). Comment out or remove this entire function:
//function getContactUsUrl(){
//
//}
- Update your local.xml
In your local.xml file, update the store_information block to use your new template file:
<default>
<reference name="footer_links">
<!-- Your existing code -->
</reference>
<reference name="store_information">
<block type="core/template" name="store.information" as="store.information" template="page/html/contacts_new.phtml"/>
</reference>
</default>
- Clear your cache
After making these changes, flush your Magento cache to ensure the changes take effect.
Conclusion
Removing the “Contact Us” link from your Magento footer isn’t a straightforward task because this link is managed differently from other footer links. However, by understanding how Magento handles this particular link and following the steps outlined above, you can achieve your goal without needing to access the contacts.xml file directly.
Remember, when working with layout updates in Magento, it’s crucial to understand which blocks and files are involved. This knowledge enables you to customize your storefront more effectively while keeping your code organized and maintainable.
For a deeper dive into Magento theme development and customization techniques, I recommend checking out our Magento Development category on the Laravel Company Blog. We cover everything from theme creation to advanced layout customizations like this one.
Happy coding!