Domanda

enter image description here

How can add a custom page link in the header Before the Welcome Message

È stato utile?

Soluzione

Please check on below URL. it shows how to add custom blog link.

Let me know if it helps.

https://zemez.io/magento/support/how-to/magento-2-1-x-manage-top-header-links/

Also, need to update theme default.xml file with below code.

<referenceBlock name="header.panel">
<block class="Magento\Cms\Block\Block" name="header_promo_top">
   <arguments>
       <argument name="block_id" xsi:type="string">header_promo_top</argument>
   </arguments>
</block>
</referenceBlock>

Altri suggerimenti

Step 1: create a CMS page. For example, we create a “Custom Link” page with an URL such as http://localhost/custom_link

Step 2: Create a default.xml file in the following path: app\code\Vendor\Module\view\frontend\layout with the following content:

<?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="header.links">
        <block class=”Vendor_name\Module_name\Block\Link" name="some_link" >
            <arguments>
                <argument name="label" xsi:type="string" translate="true">Custom link</argument>
                <argument name="path" xsi:type="string">test</argument>
            </arguments>
        </block>
    </referenceBlock>
</body>

Step 3: Create the Block class Link with the following content:

<?php
namespace Vendor\Module\Block;
class Link extends \Magento\Framework\View\Element\Html\Link
{
/**
 * Render block HTML.
 *
 * @return string
 */
protected function _toHtml()
{
    if (false != $this->getTemplate()) {
        return parent::_toHtml();
    }
    return '<li><a ' . $this->getLinkAttributes() . ' >' . $this->escapeHtml($this->getLabel()) . '</a></li>';
}
}

I hope it helps!

@Chirag Patel code almost right.

Only have to add below code after

<move element="some_link" destination="header.links" before="-"/>

or

<move element="some_link" destination="header.links" before="header"/>

after </referenceBlock> tab on default.xml.

It will move your link at first

Add this code in default.xml

 <referenceBlock name="header.links">
                <block class="Magento\Customer\Block\Account\RegisterLink" name="register-link-new"  after="-">
                    <arguments>
                        <argument name="label" xsi:type="string" translate="true">Create an Account</argument>
                    </arguments>
                </block>
                <block class="Vendor\Module\Block\Toplink" name="add.subscriptionplan.top" ifconfig="Vendor_Module/general/enable" after="-" />   
            </referenceBlock>
            <referenceBlock name="register-link" remove="true"/> 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top