How To

How to Add Dynamic Link to Footer in Magento 2

Hello Magento Family ? 

Hope you’re safe and sound. Welcome to Magento 2 How to blog series. Today’s article is on How to add Dynamic Link to Footer in Magento 2. Coincidentally, if you missed out on our last published blog [Solved] MySQL: Error while sending QUERY packet. PID=XXX” with Magento 2 Migration.

Introduction:

Footers are the major components of a website. Footers are added at the bottom of every webpage that may include page numbers, dates, copyrights, logo, or links. One can add dynamic links to the footer in order to redirect users to other essential pages of the website. Adding references to the footer helps to catch the customer’s attention and boost sales by redirecting them to make the final purchase or other information.

With the below-mentioned code, you can add Dynamic Link to Footer in your Magento 2 store to increase the user experience. Let’s go for it ?

Steps to add Dynamic Link? to Footer in Magento 2:

Step 1 : First of all, you need to Create default.xml layout file in Frontend Area. Default xml file will call each page of the website.

app/code/Vendor/Extension/view/frontend/layout/default.xml

<?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="Vendor\Extension\Block\Link" name="footer_link"/>
        </referenceBlock>
    </body>
</page>

Step 2 : Now, you need to create a Block File with the name Link.php or you can give any name which is described in the block tag under the default.xml file.

app/code/Vendor/Extension/Block/Link.php

<?php
namespace Vendor\Extension\Block;
use Magento\Framework\App\DefaultPathInterface;
use Magento\Framework\View\Element\Template\Context;
class Link extends \Magento\Framework\View\Element\Html\Link\Current
{
public function __construct(
          Context $context,
          DefaultPathInterface $defaultPath,
          array $data = []) 
    {
          parent::__construct($context, $defaultPath, $data);
     }
     public function toHtml()
     {
           return parent::toHtml();
     }
     public function getPath()
     {
          return $this->getData('path');
     }
      public function getLabel()
     {
          return __('Footer Link');
     }
}

This is how you can add a footer link to your Magento 2 store website.

Conclusion:

I hope the above solution will help you to add Dynamic Link to Footer in Magento 2. In case of any trouble, let me know in the comment section below and I will be quick to solve it. Also, share it with your Magento 2 buddies.

Happy Coding ?

Click to rate this post!
[Total: 6 Average: 4.2]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

2 days ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

4 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

4 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

5 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

6 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

1 week ago