5

I used following code for remove top links Create Account link successfully removed but Sign in link still show so can u please check and let me know what is the correction.

<referenceBlock name="top.links">
        <referenceBlock name="register-link" remove="true" />           <!--for Create Account Link-->
        <referenceBlock name="authorization-link" remove="true" />      <!--for Sign In Link  -->
    </referenceBlock>

3 Answers 3

11

Use below code for remove sign in link

 <referenceBlock name="authorization-link-login" remove="true" />
2
  • Bingo... Its Working for me Commented Aug 28, 2018 at 6:22
  • can you accept answer @PratikPatel ? Commented Aug 28, 2018 at 6:23
2

You should remove the 'authorization-link-login' block in default.xml file of your theme.

 <referenceBlock name="authorization-link-login" remove="true"/>

Remember to flush cache after that.

1
  • it is better if we write in referenceContainer header.container. Commented Oct 2, 2019 at 11:21
0

If you want to hide and show header with respect to customer login/logout

add this in body of file app/design/frontend/vendor/theme/Magento_Theme/layout/default.xml

<referenceBlock name="header.links">
            <block class="vendor\module\Block\Headerlinks" name="history-link" after="my-account-link">
                <arguments>
                    <argument name="sortOrder" xsi:type="number">100</argument>
                </arguments>
            </block>    
        </referenceBlock>

and in file Headerlinks add

    <?php
namespace vendor\module\Block;


class Headerlinks extends \Magento\Framework\View\Element\Template 
{
    protected $customerSession;

    /**
     * Construct
     *
     * @param \Magento\Framework\View\Element\Template\Context $context
     * @param \Magento\Customer\Model\Session $customerSession
     * @param array $data
     */
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
         array $data = [],
         \Magento\Customer\Model\SessionFactory $customerSession
    ) {
        parent::__construct($context, $data);
        $this->customerSession = $customerSession;
    }

    /**
     * Render block HTML
     *
     * @return string
     */
    protected function _toHtml()
    {
        $customer = $this->customerSession->create();
        if ($customer->isLoggedIn()) {
             $link = '<li><a href="' . $this->getUrl('customer/account/') . '" title="Account & Security">Account & Security</a></li>';
             $link .= '<li><a href="' . $this->getUrl('sales/order/history/') . '" title="Purchase History">Purchase History</a></li>';
        return $link;
        }
        return;
    }
}

Your Answer

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

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