How can add link in Header link Before the Welcome Message in magento 2

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


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>