0

I want to add custom link after create an account link in top header but not able to do that, please help

thanks in advance

my default.xml

    <?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="header.links">
            <block class="Test\Pro\Block\Template" name="custom_link_social_after" template="Test_Pro::html/custom_social_link_after.phtml" after="register-link"/>
        </referenceBlock>
    </body>
</page>

enter image description here

4
  • which is the parent theme you are extending?
    – Tu Van
    Oct 10, 2022 at 14:57
  • using porto theme Oct 10, 2022 at 14:59
  • which is the parent theme of porto theme? you can see it in app/design/frontend/<portoVendor>/porttoThemeName/theme.xml
    – Tu Van
    Oct 10, 2022 at 15:02
  • its using Magento/blank Oct 10, 2022 at 15:08

1 Answer 1

0

Replace your code:

<referenceBlock name="header.links">
    <block class="Test\Pro\Block\Template" name="custom_link_social_after" template="Test_Pro::html/custom_social_link_after.phtml" after="register-link"/>
</referenceBlock>

To

<referenceBlock name="top.links">
    <block class="Magento\Framework\View\Element\Html\Link" name="custom_social_link_after" template="Test_Pro::custom_social_link_after.phtml" after="register-link">
        <arguments>
            <argument name="label" xsi:type="string" translate="false">Your link label</argument>
            <argument name="path" xsi:type="string" translate="false">your-link-path</argument>
        </arguments>
    </block>
</referenceBlock>

Your phtml file <your Test_Pro module dir>/view/frontend/templates/custom_social_link_after.phtml:

<?php
/**
 * @var \Magento\Framework\View\Element\Html\Link $block
 * @var \Magento\Framework\Escaper $escaper
 */
?>
<li>
    <a href="<?= $escaper->escapeUrl($block->getHref()) ?>"
        <?php if ($title = $block->getTitle()) : ?> title="<?= $escaper->escapeHtmlAttr(__($title)) ?>"<?php endif;?>>
        <?= $escaper->escapeHtml(__($block->getLabel())) ?>
    </a>
</li>

8
  • how to add file link to this xml? Oct 10, 2022 at 16:11
  • do you mean to assign a phtml template file?
    – Tu Van
    Oct 10, 2022 at 16:12
  • yes wan to assign a phtml file Oct 10, 2022 at 16:15
  • I've updated my answer, please take a look carefully.
    – Tu Van
    Oct 10, 2022 at 16:42
  • its not working Oct 11, 2022 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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