0

Can anyone tell me how to add 'sign out' option after the user is logged in on header links in Magento 2.3.X https://prnt.sc/oqe2ue

0

If you want to add custom logout link in header than,You can add below code in test.phtml and than call this phtml in layout

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

 <?php if($customerSession->isLoggedIn()):?>       
    <li><a href="<?php echo $this->getUrl('customer/account/logout') ?>">Logout</a></li>     
 <?php endif;  ?>

Add this phtml to lyout default.xml in theme

  <referenceContainer name="header.panel.wrapper" >
     <block class="Magento\Framework\View\Element\Template" name="nameOfBlock" as="header" template="Magento_Theme::test.phtml"/>
  </referenceContainer>
  • Don't use Object Manager instance directly check this for more details: magento.stackexchange.com/questions/117098/… – Rakesh Donga Aug 9 at 9:21
  • Okk...than get the session of customer using controller or any other – moni patel Aug 9 at 9:27
  • yes create data file or block file and using \Magento\Framework\App\Http\Context $httpContext this dependency we are getting customer login or not – Rakesh Donga Aug 9 at 9:30
  • Thanx... my work is done. Can u guys tell me how to overirde block file in app folder. i want to override AuthorizationLink.php of /vendor/magento/module-customer/Block/Account. – Nafisa Aug 9 at 9:53
  • You can check this.... magenticians.com/magento-2-override-block – moni patel Aug 9 at 10:04

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.