Website footers may not be the place with great design or content, but its the place where the visitors look for the details. And the Magento 2 store owners cannot afford to miss any vital details or links in the footer.
However, the default Magento 2 footer is not up to the mark. The store owners have to modify the footer in order to deliver all the required information and the links.
Fortunately, Magento 2 is a flexible CMS that allows editing the footer.
The programmatic method to add and edit footer links in Magento 2 makes it easy for the admin to customize the footer.
Method to Add and Edit Footer Links in Magento 2:
1. Create module.xml file at app/code/Vendor/Extension/etc/ directory
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Vendor_Extension" setup_version="1.0.0"></module> </config>
2. Create registration.php file at app/code/Vendor/Extension directory
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Vendor_Extension', __DIR__ );
To remove the Privacy and Cookie Policy link from the footer:
Create default.xml file at app/code/Vendor/Extension/view/frontend/layout directory
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="privacy-policy-link" remove="true"/> </body> </page>
To add new footer link:
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="footer_links"> <block class="Magento\Framework\View\Element\Html\Link\Current" name="custom-footer-link"> <arguments> <argument name="label" xsi:type="string">Customer LInk</argument> <argument name="path" xsi:type="string">custom/extension/index/</argument> </arguments> </block> </referenceBlock> </body> </page>
That’s it.
You may also love to read our another blog post on how to remove default footer links in Magento 2.
Feel free to share the solution with the fellow developers via social media.