0

Is there a way to add a custom link in the navigation portion right after all the links? For example after Contact Us page I want to add a sign in link beside it.

enter image description here

this is what happened when I tried doing Muhammad Muiz Ather's solution. I did the "no code" one. I tried deleting the block and the widget but it's still like this. Please help

enter image description here

2 Answers 2

0

Please check following links. You'll get the idea behind it.

https://www.dckap.com/blog/add-custom-header-footer-links-magento-2/ https://aureatelabs.com/magento-2/how-to-add-custom-link-in-header-links-and-top-links-in-magento-2/

0

Easiest way to achieve this without using code is from admin panel.

In the Magento Admin(backend),

Create the block by following the below steps:

  1. Content -> Blocks
  2. Add new Block
  3. Block Title = Footer Links Block
  4. Identifier = footer_links_block
  5. Store View = All Store Views (or whatever store views it applies to, does not apply when using single store mode)
  6. Click Show/Hide Editor and enter the following (not in WYSIWYG editor):

Footer links

  1. Save

Now Create a Widget

  1. Content > Widgets
  2. Add Widget
  3. Type = CMS Static Block
  4. Design Package/Theme = Luma (or whatever theme you are using)
  5. Click Continue
  6. Widget Title = Footer Links
  7. Assign to Store Views = All Store Views (or whatever store views it applies to, does not apply when using single store mode). Now,Layout Updates:
  8. Display on All Pages
  9. Container = CMS Footer Links
  10. Widget Option > Select Block > Footer Links Block
  11. Save

Refresh the needed caches:

  1. System > Cache Management

  2. Select invalidated caches and refresh

And you are good to go! It will add your own link after the default footer links. But if you want to remove the default links and make your own then you can follow the second way of doing this.

The other way is to code.

Create a custom module based on Magento 2 structure in the folder app/code.

/app/code/Dckap/Newlink/

Create module.xml file in the below path to define your Magento 2 extension.

/app/code/Dckap/Newlink/etc/module.xml

<?xml version=“1.0”?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Dckap_Newlink" setup_version="2.0.1"></module>
</config>

Create routes.xml in the below path for your custom link.

/app/Dckap/Newlink/etc/frontend/routes.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
<router id="standard">
<route id="newlink" frontName="newlink">
<module name="Dckap_Newlink" />
</route>
</router>
</config>

/app/Dckap/Newlink/view/frontend/layout/footer.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<page>
<referenceBlock name="footer_links">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="2custom-link">
<arguments>
<argument name="label" xsi:type="string">Footer Link</argument>
<argument name="path" xsi:type="string">testuser</argument>
</arguments>
</block>
</referenceBlock>
</page>

After completing the above steps run the below Magento 2 upgrade command in the command prompt.

php bin/magento setup:upgrade

Check the browser to see your custom footer links.

3
  • I did the first part and my whole test website is just blank with only the navigation links! Commented Aug 19, 2022 at 19:08
  • I posted the edit from my post so you can see what's happening. Please help fix. Commented Aug 19, 2022 at 19:12
  • Did you flush the cache after removing the blocks and widgets? Commented Aug 22, 2022 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.