- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi guys,
can anyone help me how can i insert logout button dynamically after customer login in magento 2 forntend. After theme change i could not see logout button.
can any one help me on that ?
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @bharath553
By default in luma theme logout (Sign Out) link is there
So if you have created a custom theme - so first you need to identify exactly where you have done modification so that this link is not showing,
Or else in your header file where you have sign in link code just place the blow code over there and you will able to see the sign out link for the same .
<?xml version="1.0"?> <body> <referenceBlock name="header.links"> <block class="Company\Module\Block\Portal\PortalLink" name="partner_portal" after="-"> <arguments> <argument name="label" xsi:type="string" translate="true">Partner Portal</argument> </arguments> </block> </referenceBlock> </body>
Hope it helps !
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello @bharath553,
use below code where you want to logout button in phtml file.
<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $objectManager->create('Magento\Customer\Model\Session'); ?> <?php if($customerSession->isLoggedIn()) : ?> <li class="header_account_link_list"> <a class= "header_account_link" href="<?php echo $this->getUrl("customer/account/logout");?>"><?php echo __('Log out')?></a> </li> <?php endif;?>
you can use your own class and html tags as per your design layout.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @bharath553
By default in luma theme logout (Sign Out) link is there
So if you have created a custom theme - so first you need to identify exactly where you have done modification so that this link is not showing,
Or else in your header file where you have sign in link code just place the blow code over there and you will able to see the sign out link for the same .
<?xml version="1.0"?> <body> <referenceBlock name="header.links"> <block class="Company\Module\Block\Portal\PortalLink" name="partner_portal" after="-"> <arguments> <argument name="label" xsi:type="string" translate="true">Partner Portal</argument> </arguments> </block> </referenceBlock> </body>
Hope it helps !
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello @bharath553,
use below code where you want to logout button in phtml file.
<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $objectManager->create('Magento\Customer\Model\Session'); ?> <?php if($customerSession->isLoggedIn()) : ?> <li class="header_account_link_list"> <a class= "header_account_link" href="<?php echo $this->getUrl("customer/account/logout");?>"><?php echo __('Log out')?></a> </li> <?php endif;?>
you can use your own class and html tags as per your design layout.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: how to insert a logout button in magento 2 frontend dynamically ?
Thank you guys for your quick replay. Ill check and ill be back.
Thank you Both.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: how to insert a logout button in magento 2 frontend dynamically ?
hi guys, Actually am using SM_MEGA_MENU extesnion so that i have to add all the header links in admin side.By using that i can only add categories,page-module etc. so, i dont no where exactly i have to paste. is this possible ?
can any one guide me ?