1

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

Abdul Pathan
  • 2,802
  • 10
  • 22
Nafsss
  • 760
  • 13
  • 43

1 Answers1

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>
moni patel
  • 47
  • 11
  • Don't use Object Manager instance directly check this for more details: https://magento.stackexchange.com/questions/117098/magento-2-to-use-or-not-to-use-the-objectmanager-directly – Rakesh Donga Aug 09 '19 at 09:21
  • Okk...than get the session of customer using controller or any other – moni patel Aug 09 '19 at 09: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 09 '19 at 09: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. – Nafsss Aug 09 '19 at 09:53
  • You can check this.... https://magenticians.com/magento-2-override-block/ – moni patel Aug 09 '19 at 10:04