Any website’s header is the perfect place to display the important links. Top Links block in Magento 2 is used to add links related to customer account like Login, Logout, My Account, My Wishlist etc.

So, in this post I am going to explain how to add top link in magento 2.

First, Add or Modify below content default.xml file

Now add the Block file Toplink.php for the custom Link.

Path: app/code/Ht/Mymodule/Block/Toplink.php

Thats it. Now, Clear the cache the check for the change.

If you do not want to use the custom Block then you can use Magento default Block. In this case you don’t need to add the Block file.

Now if you want to get or show link from your template file then you can do as below.

Add or Modify below content default.xml file

Now add new template and add below code in that.

Thats it. Enjoy Magento 2!!