Links to key purchase information such as the Privacy Policy, Returns Policy, order tracking etc can be placed here to keep them informed about these important information of your website. Some site would also provide options to navigate to their site's main category sections.
Today we will delve into creating a module with which we can insert new menu items to the footer section.
Create the following files in the respective directories mentioned below:
File: registration.php
Path: path_to_magento/app/code/Velanapps/Footermenu/registration.php
Paste the following code in this file and save it:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Velanapps_Footermenu',
__DIR__
);
File: module.xml
Path: path_to_magento/app/code/Velanapps/Footermenu/etc/module.xml
Paste the following code in it and save:
<?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="Velanapps_Footermenu" setup_version="1.0.0"></module>
</config>
File: default.xml
Path: path_to_magento/app/code/Velanapps/Footermenu/view/frontend/layout/default.xml
To create a new menu item, paste the following code in it and save:
<?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="new-footer-menu-item">
<arguments>
<argument name="label" xsi:type="string">Sign Up</argument>
<argument name="path" xsi:type="string">customer/account/create/</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
To remove an existing menu item, you will have to add the following line just after the opening body tag:
<referenceBlock name="advanced-search-link" remove="true"/>
Replace the value of the 'name' attribute with the name of the menu item that you would like to remove. Here we are removing the Advanced Search Page link.
The final content of the default.xml file would be like the following:
<?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="advanced-search-link" remove="true"/>
<referenceBlock name="footer_links">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="new-footer-menu-item">
<arguments>
<argument name="label" xsi:type="string">Sign Up</argument>
<argument name="path" xsi:type="string">customer/account/create/</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Once you are done with the module, open up terminal and navigate to your magento site root directory and execute the following commands one by one:
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:flush
php bin/magento cache:clean
In case you are running the site in production mode, execute the following command as well:
php bin/magento setup:static-content:deploy