Magento 2 Customization – How to Add Custom Top Links
layoutmagento2templatetoplinks
Hello Can you help me on how to add custom top links in the header area of Magento 2,
Like this:
Best Answer
You can manage this using Static Block. In your theme default.xml you can add new static block.
File Path : Custom\tutorial\Magento_Theme\layout\default.xml
Here header_promo_top is your static block that will contain your content.
Magento 2 default theme usesheader.panel Container for showing languages switcher and skip content block in Top bar. You can get more idea about this using the below file: vendor\magento\module-theme\view\frontend\layout\default.xml
The second piece of code actually works but it does not display anything because there are no links attached to the block. page/template/links.phtml starts with this:
Not all parameters are mandatory for the addLink method. I just added them here so you can see all the possibilities. For more info take a look at this method: Mage_Page_Block_Template_Links::addLink().
The cart is pos 50 and the checkout link is pos 60. So maybe the easiest way is to position all top.links below 50. But to place just the cart link at the end you would have to rewrite the addCartLink() method.
Best Answer
You can manage this using Static Block. In your theme
default.xml
you can add new static block.File Path :
Custom\tutorial\Magento_Theme\layout\default.xml
Here
header_promo_top
is your static block that will contain your content.Magento 2 default theme uses
header.panel
Container for showing languages switcher and skip content block in Top bar. You can get more idea about this using the below file:vendor\magento\module-theme\view\frontend\layout\default.xml