Skip to main content
    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    
        <type name="Magento\Theme\Block\Html\Topmenu">
            <plugin name="navLinks
Topmenu"name="navLinksTopmenu" type="Magenik\NavLink\Plugin\Block\Topmenu" sortOrder="0" />
        </type>
    </config>
    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    
        <type name="Magento\Theme\Block\Html\Topmenu">
            <plugin name="navLinks
Topmenu" type="Magenik\NavLink\Plugin\Block\Topmenu" sortOrder="0" />
        </type>
    </config>
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Theme\Block\Html\Topmenu">
        <plugin name="navLinksTopmenu" type="Magenik\NavLink\Plugin\Block\Topmenu" sortOrder="0" />
    </type>
</config>

Now letslet's create the di.xml file that will inject our plugin in the right place.

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    
        <type name="Magento\Theme\Block\Html\Topmenu">
            <plugin name="navLinks
Topmenu" type="Magenik\NavLink\Plugin\Block\Topmenu" sortOrder="0" />
        </type>
    </config>

Topmenu" type="Magenik\NavLink\Plugin\Block\Topmenu" sortOrder="0" />

Now lets create the di.xml file that will inject our plugin in the right place.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <type name="Magento\Theme\Block\Html\Topmenu">
        <plugin name="navLinks

Topmenu" type="Magenik\NavLink\Plugin\Block\Topmenu" sortOrder="0" />

Now let's create the di.xml file that will inject our plugin in the right place.

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    
        <type name="Magento\Theme\Block\Html\Topmenu">
            <plugin name="navLinks
Topmenu" type="Magenik\NavLink\Plugin\Block\Topmenu" sortOrder="0" />
        </type>
    </config>
Source Link

You can do it by creating a simple module:

Create registration file:

app/code/Magenik/NavLink/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Magenik_NavLink',
    __DIR__
);

Create module.xml file:

app/code/Magenik/NavLink/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Magenik_NavLink" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Ui"/>
        </sequence>
    </module>
</config>

Now lets create the di.xml file that will inject our plugin in the right place.

app/code/Magenik/NavLink/etc/frontend/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <type name="Magento\Theme\Block\Html\Topmenu">
        <plugin name="navLinks

Topmenu" type="Magenik\NavLink\Plugin\Block\Topmenu" sortOrder="0" />

Create Plugin file:

app/code/Magenik/NavLink/Plugin/Block/Topmenu.php

<?php

namespace Magenik\NavLink\Plugin\Block;

use Magento\Framework\Data\Tree\NodeFactory;

class Topmenu
{

    /**
     * @var NodeFactory
     */
    protected $nodeFactory;

    /**
     * Initialize dependencies.
     *
     * @param \Magento\Framework\Data\Tree\NodeFactory $nodeFactory
     */
    public function __construct(
        NodeFactory $nodeFactory
    ) {
        $this->nodeFactory = $nodeFactory;
    }

    /**
     *
     * Inject node into menu.
     **/
    public function beforeGetHtml(
        \Magento\Theme\Block\Html\Topmenu $subject,
        $outermostClass = '',
        $childrenWrapClass = '',
        $limit = 0
    ) {
        $node = $this->nodeFactory->create(
            [
                'data' => $this->getNodeAsArray(),
                'idField' => 'id',
                'tree' => $subject->getMenu()->getTree()
            ]
        );
        $subject->getMenu()->addChild($node);
    }

    /**
     *
     * Build node
     **/
    protected function getNodeAsArray()
    {
        return [
            'name' => __('Home'),
            'id' => 'home',
            'url' => '/',
            'has_active' => true,
            'is_active' => true
        ];
    }
}

That is it!