Connect with us


How to Add Custom Header Links in Magento 2




Step 1:

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

Ex: Magento 2 root directory/app/code/vk/hd/

Step 2:

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

Magento 2 root directory/app/code/vk/hd/etc/module.xml

<?xml version=“1.0”?>

<config xmlns:xsi=”” xsi:noNamespaceSchemaLocation=”../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd”>

<module name=”vk_hd” setup_version=”2.0.1″></module>


 Step 3:

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

<?xml version=”1.0″?>

<config xmlns:xsi=”” xsi:noNamespaceSchemaLocation=”../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd”>

<router id=”standard”>

<route id=”hd” frontName=”hd”>

<module name=”vk_hd” />




Step 4:

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

<?xml version=”1.0″?>

<page xmlns:xsi=”” layout=”1column” xsi:noNamespaceSchemaLocation=”../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd”>


<referenceBlock name=”header.links”>

<move element=”test-last” destination=”header.links”/>

<block class=”vk\hd\Block\Header” name=”test-link” after=”my-account-link”/>




Step 5:

Create block file that is referred in the layout file in the below path. Magento2 root directory/app/vk/hd/Block/Header.php


namespace vk\hd\Block;

class Header extends \Magento\Framework\View\Element\Html\Link


protected $_template = ‘vk_hd::link.phtml’;

public function getHref()


return__( ‘testing’);


public function getLabel()


return __(‘Test Linking’);




Step 6:

Create template file that is referred to the block file in the below path. Magento2 root directory/app/vk/hd/frontend/templates/link.phtml


<a <?php echo $block->getLinkAttributes() ?>><?php echo $block->escapeHtml($block->getLabel())?>

<?php echo($block->getCounter()) ? ‘<span>’ . $block->escapeHtml($block->getCounter()) . ‘</span>’ : ”; ?>



Step 7:

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

php bin/magento setup:upgrade

Also Read :   UPCOMING ELECTIONS – What is at Stake?

Hi, Thank you for reading my article. I am Victor, a professional blogger from Jaipur, India.I started webetutorial for blogging & sharing solution for developer questions, and now it’s empowering globally by helping them to make money.I am writing about starting & managing a blogs, WordPress, Magento, Social Media, SEO, Marketing, making money online, Investment, Finance, Gadgets, Fitness and more.

Continue Reading
Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

1 × 4 =


Ways to Increase Comments on Your Blog




Ways to Increase Comments on Your Blog

Everyone knows commenting on the other website blogs give the benefits of backlinks, traffic, and branding of our linked website and we are trying lots of things to create a good backlinks which would give a huge converting traffic to us. Sometime people commenting a those website which doesn’t have good reputation or not a much traffic so, their efforts are not useful for them.

Commenting is the ways to drive traffic that is facebook commenting, twitter commenting or website commenting. Here we are going to tell you about some points which may give you huge traffic to increase comments on your blog.

Blog Comment Points Are:

Get visitors to subscribe: Many readers don’t want to comment at first time on your blog because they don’t have much truest on your blog and they don’t know about how much the traffic on your blog getting. To ask them to subscribe to your blog for more blog or webinar this will help to increase comments, traffic and revenue.

Also Read :   How to skip or remove shipping and payment steps from checkout in magento

Disable spam prevention methods: If you are using captcha, then you need to remove them so user can comment without any interruption.

Avoid forcing registration: If you are using registration process for commenting on your site ten remove them because this create far too much resistance and makes it much more irritate for your visitors to comment.

Link to your comments section at the end of your post: Lot of blog themes have a problem with its comment section, visitors have to scroll the whole page at the bottom for the commenting. Your blog should have comment link at the top of page with blog title where visitor can click and move directly to comment section.

Go back and think about the audience you’re trying to reach: If you are getting many comments then try to give answer of your visitors which give your attention to your visitor and help you to reach your goal and focus on the right areas.

Also Read :   WordPress- the most fashionable blogging tool!

Leave an unanswered question at the end of your post: Ask a question at the end of blog which is the one of the best ways to get readers attention to comment on your blog. Your aim should to develop a discussion within your comments and the more discussion.

Respond to comments and encourage more conversations: As we talk in Go back and think about the audience you’re trying to reach engaging your audience for getting more comments in general ways to respond to comments for further conversation.

You can let us your point of views in the comment or subscribe us to get more blog from us.

Continue Reading