Magento 2 How to add Home link in navigation bar!
How can i link my home page in the navigation bar(Home) button?
magento2 navigation home link
add a comment |
How can i link my home page in the navigation bar(Home) button?
magento2 navigation home link
None of these code working for me, could any one suggest me easy way.
– winnersingh
23 hours ago
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
– Rama Chandran M
22 hours ago
add a comment |
How can i link my home page in the navigation bar(Home) button?
magento2 navigation home link
How can i link my home page in the navigation bar(Home) button?
magento2 navigation home link
magento2 navigation home link
edited Jun 22 '18 at 4:25
Nikunj Vadariya
2,8171821
2,8171821
asked Jun 22 '18 at 3:59
PiedPiperPiedPiper
609
609
None of these code working for me, could any one suggest me easy way.
– winnersingh
23 hours ago
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
– Rama Chandran M
22 hours ago
add a comment |
None of these code working for me, could any one suggest me easy way.
– winnersingh
23 hours ago
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
– Rama Chandran M
22 hours ago
None of these code working for me, could any one suggest me easy way.
– winnersingh
23 hours ago
None of these code working for me, could any one suggest me easy way.
– winnersingh
23 hours ago
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
– Rama Chandran M
22 hours ago
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
– Rama Chandran M
22 hours ago
add a comment |
2 Answers
2
active
oldest
votes
You can do it by creating a simple module:
Create registration file:
app/code/Magenik/NavLink/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::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 let's 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="MagentoThemeBlockHtmlTopmenu">
<plugin name="navLinksTopmenu" type="MagenikNavLinkPluginBlockTopmenu" sortOrder="0" />
</type>
</config>
Create Plugin file:
app/code/Magenik/NavLink/Plugin/Block/Topmenu.php
<?php
namespace MagenikNavLinkPluginBlock;
use MagentoFrameworkDataTreeNodeFactory;
class Topmenu
{
/**
* @var NodeFactory
*/
protected $nodeFactory;
/**
* Initialize dependencies.
*
* @param MagentoFrameworkDataTreeNodeFactory $nodeFactory
*/
public function __construct(
NodeFactory $nodeFactory
) {
$this->nodeFactory = $nodeFactory;
}
/**
*
* Inject node into menu.
**/
public function beforeGetHtml(
MagentoThemeBlockHtmlTopmenu $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!
Thanks for the effort to explain it but is there a way without creating a module? Like just linking it via css or javascript?
– PiedPiper
Jun 22 '18 at 4:14
without module is not possible
– Amit Bera♦
Jun 22 '18 at 4:17
Ah okay thanks btw. I don't know the module way because i created my whole website via css, javascript and xml only.
– PiedPiper
Jun 22 '18 at 4:19
if you want to add it via js, then simply add the <li> html using js and append it to the top menu bar. But this is not the correct way to do
– Vivek
Jun 22 '18 at 5:29
If you have your custom theme inherited from magento theme then without module its possible.
– Emipro Technologies Pvt. Ltd.
Jun 22 '18 at 5:42
add a comment |
I have done by just overriding this file in my custom theme.
app/design/frontend/Vendor/theme/Magento_Theme/templates/html/topmenu.phtml
<?php
$columnsLimit = $block->getColumnsLimit() ?: 0;
$_menu = $block->getHtml('level-top', 'submenu', $columnsLimit);
$currentUrl = $block->getCurrentUrl();
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
?>
<nav class="navigation" role="navigation">
<ul data-mage-init='{"menu":{"responsive":true, "expanded":true, "position":{"my":"left top","at":"left bottom"}}}'>
<li class="level0 home <?php if($currentUrl == '/'): ?>active<?php endif; ?>"><a href="<?php echo $storeManager->getStore()->getBaseUrl(); ?>" title="<?php echo __('Home') ?>" class="level-top"><span></span></a></li>
<li class="level0 <?php if($currentUrl == '/testlink'): ?>active<?php endif; ?>"><a href="<?php echo $storeManager->getStore()->getBaseUrl().'testlink'; ?>" title="<?php echo __('Test Link') ?>" class="level-top"><span>Test Link</span></a></li>
<?php echo $_menu; ?>
</ul>
</nav>
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f230923%2fmagento-2-how-to-add-home-link-in-navigation-bar%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do it by creating a simple module:
Create registration file:
app/code/Magenik/NavLink/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::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 let's 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="MagentoThemeBlockHtmlTopmenu">
<plugin name="navLinksTopmenu" type="MagenikNavLinkPluginBlockTopmenu" sortOrder="0" />
</type>
</config>
Create Plugin file:
app/code/Magenik/NavLink/Plugin/Block/Topmenu.php
<?php
namespace MagenikNavLinkPluginBlock;
use MagentoFrameworkDataTreeNodeFactory;
class Topmenu
{
/**
* @var NodeFactory
*/
protected $nodeFactory;
/**
* Initialize dependencies.
*
* @param MagentoFrameworkDataTreeNodeFactory $nodeFactory
*/
public function __construct(
NodeFactory $nodeFactory
) {
$this->nodeFactory = $nodeFactory;
}
/**
*
* Inject node into menu.
**/
public function beforeGetHtml(
MagentoThemeBlockHtmlTopmenu $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!
Thanks for the effort to explain it but is there a way without creating a module? Like just linking it via css or javascript?
– PiedPiper
Jun 22 '18 at 4:14
without module is not possible
– Amit Bera♦
Jun 22 '18 at 4:17
Ah okay thanks btw. I don't know the module way because i created my whole website via css, javascript and xml only.
– PiedPiper
Jun 22 '18 at 4:19
if you want to add it via js, then simply add the <li> html using js and append it to the top menu bar. But this is not the correct way to do
– Vivek
Jun 22 '18 at 5:29
If you have your custom theme inherited from magento theme then without module its possible.
– Emipro Technologies Pvt. Ltd.
Jun 22 '18 at 5:42
add a comment |
You can do it by creating a simple module:
Create registration file:
app/code/Magenik/NavLink/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::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 let's 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="MagentoThemeBlockHtmlTopmenu">
<plugin name="navLinksTopmenu" type="MagenikNavLinkPluginBlockTopmenu" sortOrder="0" />
</type>
</config>
Create Plugin file:
app/code/Magenik/NavLink/Plugin/Block/Topmenu.php
<?php
namespace MagenikNavLinkPluginBlock;
use MagentoFrameworkDataTreeNodeFactory;
class Topmenu
{
/**
* @var NodeFactory
*/
protected $nodeFactory;
/**
* Initialize dependencies.
*
* @param MagentoFrameworkDataTreeNodeFactory $nodeFactory
*/
public function __construct(
NodeFactory $nodeFactory
) {
$this->nodeFactory = $nodeFactory;
}
/**
*
* Inject node into menu.
**/
public function beforeGetHtml(
MagentoThemeBlockHtmlTopmenu $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!
Thanks for the effort to explain it but is there a way without creating a module? Like just linking it via css or javascript?
– PiedPiper
Jun 22 '18 at 4:14
without module is not possible
– Amit Bera♦
Jun 22 '18 at 4:17
Ah okay thanks btw. I don't know the module way because i created my whole website via css, javascript and xml only.
– PiedPiper
Jun 22 '18 at 4:19
if you want to add it via js, then simply add the <li> html using js and append it to the top menu bar. But this is not the correct way to do
– Vivek
Jun 22 '18 at 5:29
If you have your custom theme inherited from magento theme then without module its possible.
– Emipro Technologies Pvt. Ltd.
Jun 22 '18 at 5:42
add a comment |
You can do it by creating a simple module:
Create registration file:
app/code/Magenik/NavLink/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::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 let's 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="MagentoThemeBlockHtmlTopmenu">
<plugin name="navLinksTopmenu" type="MagenikNavLinkPluginBlockTopmenu" sortOrder="0" />
</type>
</config>
Create Plugin file:
app/code/Magenik/NavLink/Plugin/Block/Topmenu.php
<?php
namespace MagenikNavLinkPluginBlock;
use MagentoFrameworkDataTreeNodeFactory;
class Topmenu
{
/**
* @var NodeFactory
*/
protected $nodeFactory;
/**
* Initialize dependencies.
*
* @param MagentoFrameworkDataTreeNodeFactory $nodeFactory
*/
public function __construct(
NodeFactory $nodeFactory
) {
$this->nodeFactory = $nodeFactory;
}
/**
*
* Inject node into menu.
**/
public function beforeGetHtml(
MagentoThemeBlockHtmlTopmenu $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!
You can do it by creating a simple module:
Create registration file:
app/code/Magenik/NavLink/registration.php
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::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 let's 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="MagentoThemeBlockHtmlTopmenu">
<plugin name="navLinksTopmenu" type="MagenikNavLinkPluginBlockTopmenu" sortOrder="0" />
</type>
</config>
Create Plugin file:
app/code/Magenik/NavLink/Plugin/Block/Topmenu.php
<?php
namespace MagenikNavLinkPluginBlock;
use MagentoFrameworkDataTreeNodeFactory;
class Topmenu
{
/**
* @var NodeFactory
*/
protected $nodeFactory;
/**
* Initialize dependencies.
*
* @param MagentoFrameworkDataTreeNodeFactory $nodeFactory
*/
public function __construct(
NodeFactory $nodeFactory
) {
$this->nodeFactory = $nodeFactory;
}
/**
*
* Inject node into menu.
**/
public function beforeGetHtml(
MagentoThemeBlockHtmlTopmenu $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!
edited Jun 22 '18 at 9:03
Dhaduk Mitesh
655217
655217
answered Jun 22 '18 at 4:12
Nikunj VadariyaNikunj Vadariya
2,8171821
2,8171821
Thanks for the effort to explain it but is there a way without creating a module? Like just linking it via css or javascript?
– PiedPiper
Jun 22 '18 at 4:14
without module is not possible
– Amit Bera♦
Jun 22 '18 at 4:17
Ah okay thanks btw. I don't know the module way because i created my whole website via css, javascript and xml only.
– PiedPiper
Jun 22 '18 at 4:19
if you want to add it via js, then simply add the <li> html using js and append it to the top menu bar. But this is not the correct way to do
– Vivek
Jun 22 '18 at 5:29
If you have your custom theme inherited from magento theme then without module its possible.
– Emipro Technologies Pvt. Ltd.
Jun 22 '18 at 5:42
add a comment |
Thanks for the effort to explain it but is there a way without creating a module? Like just linking it via css or javascript?
– PiedPiper
Jun 22 '18 at 4:14
without module is not possible
– Amit Bera♦
Jun 22 '18 at 4:17
Ah okay thanks btw. I don't know the module way because i created my whole website via css, javascript and xml only.
– PiedPiper
Jun 22 '18 at 4:19
if you want to add it via js, then simply add the <li> html using js and append it to the top menu bar. But this is not the correct way to do
– Vivek
Jun 22 '18 at 5:29
If you have your custom theme inherited from magento theme then without module its possible.
– Emipro Technologies Pvt. Ltd.
Jun 22 '18 at 5:42
Thanks for the effort to explain it but is there a way without creating a module? Like just linking it via css or javascript?
– PiedPiper
Jun 22 '18 at 4:14
Thanks for the effort to explain it but is there a way without creating a module? Like just linking it via css or javascript?
– PiedPiper
Jun 22 '18 at 4:14
without module is not possible
– Amit Bera♦
Jun 22 '18 at 4:17
without module is not possible
– Amit Bera♦
Jun 22 '18 at 4:17
Ah okay thanks btw. I don't know the module way because i created my whole website via css, javascript and xml only.
– PiedPiper
Jun 22 '18 at 4:19
Ah okay thanks btw. I don't know the module way because i created my whole website via css, javascript and xml only.
– PiedPiper
Jun 22 '18 at 4:19
if you want to add it via js, then simply add the <li> html using js and append it to the top menu bar. But this is not the correct way to do
– Vivek
Jun 22 '18 at 5:29
if you want to add it via js, then simply add the <li> html using js and append it to the top menu bar. But this is not the correct way to do
– Vivek
Jun 22 '18 at 5:29
If you have your custom theme inherited from magento theme then without module its possible.
– Emipro Technologies Pvt. Ltd.
Jun 22 '18 at 5:42
If you have your custom theme inherited from magento theme then without module its possible.
– Emipro Technologies Pvt. Ltd.
Jun 22 '18 at 5:42
add a comment |
I have done by just overriding this file in my custom theme.
app/design/frontend/Vendor/theme/Magento_Theme/templates/html/topmenu.phtml
<?php
$columnsLimit = $block->getColumnsLimit() ?: 0;
$_menu = $block->getHtml('level-top', 'submenu', $columnsLimit);
$currentUrl = $block->getCurrentUrl();
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
?>
<nav class="navigation" role="navigation">
<ul data-mage-init='{"menu":{"responsive":true, "expanded":true, "position":{"my":"left top","at":"left bottom"}}}'>
<li class="level0 home <?php if($currentUrl == '/'): ?>active<?php endif; ?>"><a href="<?php echo $storeManager->getStore()->getBaseUrl(); ?>" title="<?php echo __('Home') ?>" class="level-top"><span></span></a></li>
<li class="level0 <?php if($currentUrl == '/testlink'): ?>active<?php endif; ?>"><a href="<?php echo $storeManager->getStore()->getBaseUrl().'testlink'; ?>" title="<?php echo __('Test Link') ?>" class="level-top"><span>Test Link</span></a></li>
<?php echo $_menu; ?>
</ul>
</nav>
add a comment |
I have done by just overriding this file in my custom theme.
app/design/frontend/Vendor/theme/Magento_Theme/templates/html/topmenu.phtml
<?php
$columnsLimit = $block->getColumnsLimit() ?: 0;
$_menu = $block->getHtml('level-top', 'submenu', $columnsLimit);
$currentUrl = $block->getCurrentUrl();
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
?>
<nav class="navigation" role="navigation">
<ul data-mage-init='{"menu":{"responsive":true, "expanded":true, "position":{"my":"left top","at":"left bottom"}}}'>
<li class="level0 home <?php if($currentUrl == '/'): ?>active<?php endif; ?>"><a href="<?php echo $storeManager->getStore()->getBaseUrl(); ?>" title="<?php echo __('Home') ?>" class="level-top"><span></span></a></li>
<li class="level0 <?php if($currentUrl == '/testlink'): ?>active<?php endif; ?>"><a href="<?php echo $storeManager->getStore()->getBaseUrl().'testlink'; ?>" title="<?php echo __('Test Link') ?>" class="level-top"><span>Test Link</span></a></li>
<?php echo $_menu; ?>
</ul>
</nav>
add a comment |
I have done by just overriding this file in my custom theme.
app/design/frontend/Vendor/theme/Magento_Theme/templates/html/topmenu.phtml
<?php
$columnsLimit = $block->getColumnsLimit() ?: 0;
$_menu = $block->getHtml('level-top', 'submenu', $columnsLimit);
$currentUrl = $block->getCurrentUrl();
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
?>
<nav class="navigation" role="navigation">
<ul data-mage-init='{"menu":{"responsive":true, "expanded":true, "position":{"my":"left top","at":"left bottom"}}}'>
<li class="level0 home <?php if($currentUrl == '/'): ?>active<?php endif; ?>"><a href="<?php echo $storeManager->getStore()->getBaseUrl(); ?>" title="<?php echo __('Home') ?>" class="level-top"><span></span></a></li>
<li class="level0 <?php if($currentUrl == '/testlink'): ?>active<?php endif; ?>"><a href="<?php echo $storeManager->getStore()->getBaseUrl().'testlink'; ?>" title="<?php echo __('Test Link') ?>" class="level-top"><span>Test Link</span></a></li>
<?php echo $_menu; ?>
</ul>
</nav>
I have done by just overriding this file in my custom theme.
app/design/frontend/Vendor/theme/Magento_Theme/templates/html/topmenu.phtml
<?php
$columnsLimit = $block->getColumnsLimit() ?: 0;
$_menu = $block->getHtml('level-top', 'submenu', $columnsLimit);
$currentUrl = $block->getCurrentUrl();
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$storeManager = $objectManager->get('MagentoStoreModelStoreManagerInterface');
?>
<nav class="navigation" role="navigation">
<ul data-mage-init='{"menu":{"responsive":true, "expanded":true, "position":{"my":"left top","at":"left bottom"}}}'>
<li class="level0 home <?php if($currentUrl == '/'): ?>active<?php endif; ?>"><a href="<?php echo $storeManager->getStore()->getBaseUrl(); ?>" title="<?php echo __('Home') ?>" class="level-top"><span></span></a></li>
<li class="level0 <?php if($currentUrl == '/testlink'): ?>active<?php endif; ?>"><a href="<?php echo $storeManager->getStore()->getBaseUrl().'testlink'; ?>" title="<?php echo __('Test Link') ?>" class="level-top"><span>Test Link</span></a></li>
<?php echo $_menu; ?>
</ul>
</nav>
answered Aug 30 '18 at 13:30
Ravi OzaRavi Oza
1338
1338
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f230923%2fmagento-2-how-to-add-home-link-in-navigation-bar%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
None of these code working for me, could any one suggest me easy way.
– winnersingh
23 hours ago
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
– Rama Chandran M
22 hours ago