I would like to remove My Account link from top links, when customer is not logged in.

How do I achieve it via XML layout files?


You can do it without xml file also which will be easier for your task. First step that you have to do is override header part and once its done apply some simple logic like by checking cx is logged in or not.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');

if($customerSession->isLoggedIn()) {//apply logic here}

You can remove via overriding theme layout or xml file.


<referenceBlock name="top.links">
    <referenceBlock name="register-link" remove="true" />           <!--for Create Account Link-->
    <referenceBlock name="my-account-link" remove="true" />         <!--for My Account Link-->

I hope this will help you

  • This will always remove My Account link, I need to remove it only when the customer is logged out – gianis6 Feb 8 '17 at 9:49
  • I need to display My Account link only for logged in customer – gianis6 Feb 8 '17 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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