Want to know how to display "My Account" only after customer LogIn. After LogOut it will again be hidden on the same place. New to Magento 2

thx for help

1 Answer 1


The customer_logged_* layout handles used in M1 were removed in M2. Below is a small plugin using a method similar to what's used in core for adding/removing the "Register" top link in Magento\Customer\Block\Account\RegisterLink


namespace Vendor\Module\Plugin;

use Magento\Customer\Model\Context;

class Link
    protected $httpContext;
    public function __construct(
        \Magento\Framework\App\Http\Context $context
    ) {
        $this->httpContext = $context;
    public function afterToHtml(\Magento\Customer\Block\Account\Link $subject, $result)
        if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) {
            return $result;
        return '';


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Customer\Block\Account\Link">
        <plugin name="vendor_module_toplinks_myaccount" type="Vendor\Module\Plugin\Link" sortOrder="10" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.