I have modified a themes account_links.phtml
file. Client has requested that it just says "Login" and if logged in it should just show "My Account".
This is the code I came up with:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
?>
<div id="header-account" class="account-links top-links links-wrapper-separators-left skip-content skip-content--style">
<?php if ($customerSession->isLoggedIn()): ?>
<ul class="header links">
<li class="authorization-link" data-label="or">
<a href="<?php echo $block->getUrl('customer/account') ?>">My Account</a>
</li>
</ul>
<?php else: ?>
<ul class="header links">
<li class="authorization-link" data-label="or">
<a href="<?php echo $block->getUrl('customer/account/login') ?>">Login</a>
</li>
</ul>
<?php endif; ?>
</div>
This works if the cache is disabled but if cache is enabled then it always shows "Login".
How do I make it so that this isn't broken by the cache as site needs the cache enabled.