I have a block to add link at top based on if customer login like this, when i'm at myaccount page the header link show the right one, but when i go to other page it shows the wrong one, here's my code:


namespace Namespace\Module\Block;

class Link extends \Magento\Framework\View\Element\Html\Link

protected function _toHtml()
     if (false != $this->getTemplate()) {
     return parent::_toHtml();
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
     $customerSession = $objectManager->get('Magento\Customer\Model\Session');
     if($customerSession->isLoggedIn()) {
       return '<li><a href="/test/loggedin" > Logged In </a></li>' ;
     } else {
       return '<li><a href="/test/notloggedin" > Not Logged In </a></li>';
  • please let me know if you have issue Aug 3 '17 at 6:05
  • when full page cache enable it will not work like that way there is another way to check this please find it on google it may help you. Jul 29 '19 at 13:50

You have to set cacheable="false" your module with xml file like this,

<block class="Namespace\Module\Block\Link" name="customname" cacheable="false">

Remove var/generation and clear cache.


Simple add this block code in cms or block content

{{block class="Magento\Customer\Block\Account\AuthorizationLink" name="authorization-link" template="account/link/authorization.phtml"/}}

it will show you signin or signout

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.