In my case, i have two type of customer: for local customer i will keep the firstname lastname in top link if it's connected else i want to display a custom attribute that i added in registration form so i will have instead this information and then the dropdown in top link so how to proceed please any help ? enter image description here


2 Answers 2


Please try below code

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $customerRepositoryInterface = $objectManager->create('\Magento\Customer\Api\CustomerRepositoryInterface');
    $customerSession = $objectManager->create('Magento\Customer\Model\Session');
    if($customerSession->isLoggedIn()) {
        $customerId = $customerSession->getCustomer()->getId();
        $customeratt = $customerRepositoryInterface->getById($customerId);
        $customAttributeCode = 'custom_name';
        echo $cattrValue = $customeratt->getCustomAttribute($customAttributeCode); //Please echo this line when you want display custom name.
  • thanks for your replay just one question where to put this code Jan 23, 2019 at 8:37
  • Override this file into your theme and put in respective <li> tag vendor/magento/module-customer/view/frontend/templates/account/customer.phtml Jan 23, 2019 at 10:13
  • i tried this and i get a white page with just icon of language and the label skip menu Jan 28, 2019 at 16:38

Turn on debug hint mode in BO and override in theme

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.