Magento Expert Forum - Improve your Magento experience

Results 1 to 8 of 8

How to Include Custom Header Links in Magento 2?

  1. #1
    Junior Member
    Join Date
    May 2015
    Posts
    36
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default How to Include Custom Header Links in Magento 2?


  2. #2
    Junior Member
    Join Date
    Dec 2016
    Posts
    77
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    Thanks for sharing, I'll visit the website later

  3. #3
    Junior Member
    Join Date
    Dec 2016
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Step 1:
    Create a custom module based on Magento 2 structure in the folder app/code.
    Ex: Magento 2 root directory/app/code/Dckap/Newlink/

    Step 2:
    Create module.xml file in the below path to define your Magento 2 extension.
    Magento 2 root directory/app/code/Dckap/Newlink/etc/module.xml

    Code:
    <?xml version=“1.0”?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Dckap_Newlink" setup_version="2.0.1"></module>
    </config>
    Step 3:
    Create routes.xml in the below path for your custom link.
    Magento 2 root directory/app/Dckap/Newlink/etc/frontend/routes.xml

    Code:
    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
    <router id="standard">
    <route id="newlink" frontName="newlink">
    <module name="Dckap_Newlink" />
    </route>
    </router>
    </config>
    Step 4:
    Create layout file in the below path for a custom header.
    Magento2 root directory/app/Dckap/Newlink/view/frontend/layout/header.xml

    Code:
    <?xml version="1.0"?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <body>
    <referenceBlock name="header.links">
    <move element="test-last" destination="header.links"/>
    <block class="Dckap\Newlink\Block\Header" name="test-link" after="my-account-link"/>
    </referenceBlock>
    </body>
    </page>
    Step 5:
    Create block file that is referred in the layout file in the below path.
    Magento2 root directory/app/Dckap/Newlink/Block/Header.php
    Code:
    <?php
    namespace Dckap\Newlink\Block;
    class Header extends \Magento\Framework\View\Element\Html\Link
    {
    protected $_template = 'Dckap_Newlink::link.phtml';
    public function getHref()
    {
    return__( 'testuser');
    }
    public function getLabel()
    {
    return __('Test Link');
    }
    }
    ?>
    Step 6:
    Create template file that is referred to the block file in the below path.
    Magento2 root directory/app/Dckap/Newlink/frontend/templates/link.phtml


    Code:
    <li>
    <a <?php echo $block->getLinkAttributes() ?>><?php echo $block->escapeHtml($block->getLabel())?>
    <?php echo($block->getCounter()) ? '<span>' . $block->escapeHtml($block->getCounter()) . '</span>' : ''; ?>
    </a>
    </li>
    Step 7:
    After completing the above steps run the below Magento2 upgrade command in the command prompt:
    php bin/magento setup:upgrade

    After running the above command, clear all the Magento cache and check whether the extension is installed successfully in the Magento 2 admin side.

  4. #4
    New member
    Join Date
    Dec 2016
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Need urgent help with Magento 2? We can fix your store right now!

    More than 150 tech geeks are available for Magento requests to support and enhance your store 24/7.

    You can sign up for no commitment, On-Demand support agreement. It allows you to get an instant access to a team of Certified Magento Developers and Certified Magento Solution Specialists only when you need them.

    Our team has launched & supported over 400 Magento stores for both small startups and Fortune 500 brands in 35 countries.

    How to apply?
    Simply send a request and your contact details to [email protected] or setup a meeting @scandiweb.com/contact

    For more info, check scandiweb.com/services/247-magento-support?utm_source=frm

    P.S. Check it out
    - Behind the scene of our 24/7 Support: https://www.youtube.com/watch?v=NAmGNq5N6UY
    - Spy on our Support team and the way we live: https://stories.scandiweb.com/how-to...ts-bbfc4acd386
    - We work as hard as we party and if we party - we set Guinness Records: https://www.youtube.com/watch?v=kUgLD_A3WP8

  5. #5
    New member
    Join Date
    Jan 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Header & Footer Links help user navigate and find relevant content. The blog explains how to add custom header & Footer Links in Magento 2.

    Magento 2 Invalid Form Key. Please refresh the page
    Advantages of mobile commerce
    How to fix Magento error There has been an error processing your request
    How to solve Magento 403 forbidden error

  6. #6
    Junior Member Ecomsolver's Avatar
    Join Date
    Jul 2018
    Location
    Jaipur,India
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    As you may know, a header is the key element of a website as it is the first thing that people will see when they land on your site. Basically, it contains links to important pages on your site that potential customers will often want to visit before making a purchase or enquiry. It sets the tone for the whole site. You need to include adequate information in the header to encourage your customers to explore your site further. We presented the way to Add Custom Header in Magento 2 so kindly visit here.

  7. #7
    Junior Member
    Join Date
    Sep 2018
    Location
    Oman, Muscat
    Posts
    2,084
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default

    Header/Top connections segment in Magento is the default square commonly used to make an individual zone . Include the Custom Link. We will likewise tell you the best way to include a contact connect (CMS page based) to the Magento 2 top connections header.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •