2

This question already has an answer here:

In Magento 2, I want to add custom cms page link in header menu before wishlist link.

Please tell me how we can add custom page link before wishlist link?

marked as duplicate by Qaisar Satti, 7ochem, Fabian Schmengler, Amit Bera, Rajeev K Tomy Aug 24 '16 at 9:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Which is theme are you use in ? – Suresh Chikani Aug 23 '16 at 9:13
2

You have to add bellow code to in your theme default.xml

<referenceBlock name="top.links">
    <block class="Magento\Framework\View\Element\Html\Link\Current" name="cms-page-name"  before="wish-list-link">
        <arguments>
            <argument name="label" xsi:type="string">cms-page-name</argument>
            <argument name="path" xsi:type="string">cms-page-path</argument>
        </arguments>
    </block>
</referenceBlock>

Clean cache and check.

Let me know if you have any difficulty.

0

you have to just override template file for wishlist into your theme.

path,

app/design/frontend/Vendorname/themename/Magento_Wishlist/templates/link.phtml

Now you can write down your cms page link code before wishlist code, this tag.

<?php $link = 'Cms page link'; ?>
    <div class="link cmspage">
        <a <?php echo $link; ?>>CMS Page</a>
    </div>
0

In Namespace/ModuleName/view/frontend/layout/default.xml

<?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>
    <referenceContainer name="header.container">
        <block class="Magento\Framework\View\Element\Html\Links" name="top.links">
                    <arguments>
                        <argument name="css_class" xsi:type="string">header links</argument>
                    </arguments>
                    <block class="Namespace\ModuleName\Block\Links\Link" name="linkname" before='wish-list-link'/>
                </block>
     </referenceContainer>

</body> 

Namespace\ModuleName\Block\Links\Link.php

<?php
namespace Namespace\ModuleName\Block\Links;
class Link extends \Magento\Framework\View\Element\Html\Link
{
public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    array $data = []
) {
    parent::__construct($context, $data);
}

public function getHref(){

    $page_url = '[cms url key]'; 
    return $this->getUrl($page_url);
}

public function getLabel(){
     return '[Link Name]';
}
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.