The header and footer are key elements of a website. Typically, they contain links to important pages on your site that potential customers will often want to visit before making a purchase or enquiry.

Add Custom Header and Footer Links

The header is the first thing that people will see when they land on your site. It sets the tone for the whole site. You need to include enough information in the header to encourage customers to explore your site further.

The footer of a website is just as important as the header, as it is the last chance for you to grab a customer’s attention and encourage them to complete an action, such as making a purchase or requesting information.

By following the steps mentioned below you can create your custom header and footer links and make your site more attractive and clear.

How to Add Custom Header Links in Magento 2?

Step 1:

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

Ex: Magento 2 root directory/app/code/Dckap/Newlink/
Step 2:

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

Magento 2 root directory/app/code/Dckap/Newlink/etc/module.xml

 Step 3:

Create routes.xml in the below path for your custom link.
Magento 2 root directory/app/Dckap/Newlink/etc/frontend/routes.xml

Step 4:

Create layout file in the below path for a custom header.
Magento2 root directory/app/Dckap/Newlink/view/frontend/layout/header.xml

 Step 5:

Create block file that is referred in the layout file in the below path.

Magento2 root directory/app/Dckap/Newlink/Block/Header.php

For third party URLs follow the above code.

Step 6:

Create template file that is referred to the block file in the below path.

Magento2 root directory/app/Dckap/Newlink/frontend/templates/link.phtml

Step 7:

After completing the above steps run the below Magento2 upgrade command in the command prompt:

After running the above command, clear all the Magento cache and check whether the extension is installed successfully in the Magento 2 admin side.

p1-tiny

p2-tiny

How to Add Custom Footer Links in Magento 2?

Step 1:

Now to add custom footer link follow the above first 3 steps and replace the layout file with the below code:

Magento2 root directory/app/Dckap/Newlink/view/frontend/layout/footer.xml

There are 2 ways of getting the argument values:
1.By using block file. (used for header link)
2.By specifying argument values in the layout file.(used for footer link)

Now follow the above step(step 7).

Check the browser to see your custom header and footer links.

p3-tiny

p4-tiny

Hope this blog helped you to add custom header and footer links in Magento2.

Be the first to Know

Subscribe to our blog to get the latest articles directly to your inbox.

READY TO DRIVE SALES?

Request a Quote Today

Request a Quote

Leave a Reply

17 Comments on "How to Add Custom Header and Footer Links in Magento 2?"


Guest
jayaprakahs
5 months 1 day ago

Hi Gayathri,

I can’t see the header and footer in check out page what can I do?
what I missed I don’t know .
thanks, jayaprakash
jayaprakash676@gmail.com -9677393154

Guest
Abhinandan Dev
5 months 28 minutes ago

Hi @Jayaprakahs its default functionality or for security reason no ecommerce CMS displays both header and footer links on checkout Page

Guest
Smithd649
7 months 7 days ago

I’m curious to uncover out what weblog system youre employing? Im experiencing some small security problems with my latest weblog and Id like to locate something a lot more safeguarded. Do you have any recommendations? cbcdgfdkddcbdbbe

Guest
manali
11 months 5 days ago

hi,
how to add category list in footer in magento 2

admin
Admin
11 months 1 day ago

Hi,

Here is the reply…

1.Overwrite the Magento_Theme module in your theme

2.Goto view->frontend->layout->default.xml

3.Add the below line of code under

4.Clear the cache

5.Refresh the frontend

Let us know if this is useful
subscribe to our blogs.
Thanks.

Guest
manali
11 months 5 days ago

hi, I want to add the list of category in footer in magento 2.. so, can you please help me ???

admin
Admin
11 months 1 day ago

Hi,

Here is the reply…

1.Overwrite the Magento_Theme module in your theme

2.Goto view->frontend->layout->default.xml

3.Add the below line of code under

4.Clear the cache

5.Refresh the frontend

Let us know if this is useful
subscribe to our blogs.
Thanks.

Guest
DIJTIH KUMAR P
11 months 27 days ago

Hi,
i tried to add custom links to header, in magento 2.1.8 but couldn’t see in any link in header,but its working in footer very perfect..I followed according to your tutorial but can’t make change in header.Please help me..

admin
Admin
11 months 17 days ago

Hi Dijith,

Thanks for your comments.

You need to change the file from header.xml to default.xml in step 4 and need to replace the following code to link.phtml file in step 6.

escapeHtml($block->getLabel())?>
getCounter()) ? ” . $block->escapeHtml($block->getCounter()) . ” : ”; ?>

Hope this resolved your issue. Please let us know if you have further queries.
Thanks and subscribe to our blogs.

Guest
Alex
1 year 4 months ago

Hi Gayathri,

I appreciate your work on producing this article, i was looking for help in creating layout with some integration and got helped by your article in header and footer, but for Magento 2 Layouts, Blocks, And Templates i found this, After creating the directory structure, we will now declare and register our theme by adding theme.xml and registration.php so that Magento 2 registers the theme’s existence.

Author
1 year 3 months ago

Hi Alex,

Thanks for sharing this.
Good to know you found what you needed.
Please keep reading our blogs and share your insights, comments and feedbacks.

Guest
Zayan Vigoli
1 year 4 months ago

Good post

admin
Admin
1 year 4 months ago

Hi Alex,

Thanks so much for your appreciation.
Please subscribe to our blogs for more such posts.

Guest
cherrysmith
1 year 10 months ago

Nice Post. Thanks for Sharing. Also, check out this blog to learn simple and effective method to Include Custom Header Links in Magento 2. Click: goo.gl/rpHAQ6

admin
Admin
1 year 10 months ago

Hi Cherry,

Thanks for sharing.
Please keep reading our blogs and posting comments.

Guest
monika
2 years 4 days ago

header module is not working please give me solution for that how can i add custom module header in magento 2?

Guest
Nir Goldman
2 years 5 months ago

1. you forgot to put registerion.php
2.module not work at all

Thanks anyway