I want to show customer first name and last name after logged in Magento2.2.5? As default magento fetches the first name and last name after logged in.

In my case, I have removed magento default first name and last name and added custom first name and last name for some customization purpose.

After adding my custom fields, the first name and last name is not shown in header after customer logged in Magento2.2.5?

Please someone guide me on this.

Any help would be appreciated.

Thanks in advance.

  • Why & where from you remove First name & Last name ? from code, database etc..? May 1, 2019 at 11:39

3 Answers 3


Get customer session and display name of customer using below code.
Add below code in your file.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$customerSession = $objectManager->get('Magento\Customer\Model\Session');

<?php if($customerSession->isLoggedIn()):?>
    <a href="<?php echo $this->getUrl('customer/account') ?>">Welcome! <?php 
       echo $customerSession->getCustomer()->getName(); ?>

You need to do following things.

  1. create your block file with following code :

    protected $_customerSession;
    public function __construct(\Magento\Customer\Model\Session $customerSession) {
    $this->_customerSession = $customerSession;
    public function getCustomerInfo()
        return $this->_customerSession->getCustomer(); 
  2. Now call the code into your phtml file like this.

    $customerdata = $block->getCustomerInfo();
    echo $customerdata->getCustomFirstNameField();
    echo $customerdata->getCustomLastNameField();

Using object manager into your phtml file

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->create('Magento\Customer\Model\Session');

if ($customerSession->isLoggedIn()) {

 $customerSession->getCustomerId();  // get Customer Id

echo $customerSession->getCustomer()->getName();  // get  Full Name
echo $customerSession->getCustomer()->getEmail(); // get Email


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.