Magento – Magento 2 : Remove Top Links When Customer Not Logged In

customerlayoutlinkmagento2toplinks

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?

Best Answer

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}