How can I display customer name in the header after logged in successfully?


Go to your current theme and your current header, some themes uses different headers : app/design/frontend/default/themek/te‌​mplate/page/html/hea‌​der.phtml for exemple then add this:

<?php if ( Mage::getSingleton('customer/session')->isLoggedIn() ): ?>
    <div class="customer-name">    
        <?php echo Mage::getSingleton('customer/session')->getCustomer()->getName(); ?>
<?php endif; ?>
  • Customer name display only in account page, i need to display in header part also like, eg: Hi, Customer_Name – zus Sep 5 '17 at 6:07
  • No, with this code the customer name will be displayed in all pages because we added it in header and the header is displayed in all pages no ? Or you want to display it just in account page ? – PЯINCƏ Sep 5 '17 at 6:20
  • I need, customer name display on all pages at the header. but your code customer name display only in the account page. – zus Sep 5 '17 at 6:23
  • actually my mistake, I placed as a wrong position. now okay, but its display like below the menu bar. how can I display on the top header? – zus Sep 5 '17 at 6:26
  • 1
    <?php echo 'Hi'.'&nbsp;'.Mage::getSingleton('customer/session')->getCustomer()->getN‌​ame(); ?> – PЯINCƏ Sep 5 '17 at 7:41

Try this:

EDIT: file location: app/design/frontend/your_package/your_theme/template/page/html/header.phtml

Add these in this file where you want to get the name to be shown.

<?php if (Mage::getSingleton('customer/session')->isLoggedIn()): ?>

<?php echo Mage::getSingleton('customer/session')->getCustomer()->getName() ?>

<?php endif; ?>
  • Where i can add these lines – zus Sep 4 '17 at 13:03
  • @zus see my edited answer. – Yogesh Agarwal Sep 4 '17 at 13:09
  • I need the message display at the header, like eg: hi, customer name. – zus Sep 4 '17 at 13:13
  • please open the header.phtml and find the place. then add the code.. Can't tell you the exact location in the file.. its up to you – Yogesh Agarwal Sep 4 '17 at 13:19

When the customer is logged in, you can get customer session in frontend from any phtml file.

To show customer name in header, you would need to open header.phtml file located at:


folder and write below code where you want to display current logged in customer name:

if (Mage::getSingleton('customer/session')->isLoggedIn()) {
echo Mage::getSingleton('customer/session')->getCustomer()->getName();

Please let me know if you find any problem.

  • app/design/frontend/default/theme/template/page/html, name display only in account page, not header page. – zus Sep 4 '17 at 13:28
  • Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home/root/public_html/app/design/frontend/default/themek/template/page/html/header.phtml on line 176 how to solve this error – zus Sep 4 '17 at 13:30
  • Please see updated answer. I have fixed the error. – Mohit Kumar Arora Sep 4 '17 at 13:50

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.