---
title: "How to Add Customer Name in CMS Page/Block in Magento 2?"
url: "https://magecomp.com/blog/add-customer-name-in-cms-page-block-in-magento-2/"
date: "2021-01-22T14:37:08+00:00"
modified: "2025-02-20T10:51:30+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 288
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "Customize your CMS Page or Block to increase user experience. Learn How to Add Customer Name in CMS Page/Block in Magento 2."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Magento 2: How Resize Image of Specific Products Based on Admin Configuration?"
    url: "https://magecomp.com/blog/magento-2-resize-image-of-specific-products-based-on-admin-configuration/"
  - title: "How to Programmatically Clear Shopping Cart in Magento 2"
    url: "https://magecomp.com/blog/programmatically-clear-shopping-cart-magento-2/"
  - title: "Magento 2: Check if the Current Area is Frontend or Backend"
    url: "https://magecomp.com/blog/magento-2-check-current-area-is-frontend-or-backend/"
---

# How to Add Customer Name in CMS Page/Block in Magento 2?

_Published: January 22, 2021_  
_Author: Dhiren Vasoya_  

![How to Add Customer Name in CMS Page Block in Magento 2](https://magecomp.com/blog/wp-content/uploads/2021/01/How-to-Add-Customer-Name-in-CMS-Page-Block-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

Welcome to the “How To” Magento 2 Blog series. Today’s topic to learn about is How to Add Customer Name in CMS Page/Block in Magento 2.
[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-3.webp)](https://magecomp.com/services/magento-upgrade-services/)

## Introduction:
74% of people feel frustrated if the website content is not personalized and stops them from shopping. Hence, customization helps in boosting the user experience of your store and enhance sales. With Magento 2, you can customize everything from the look of the website to product categories and their features.
With Magento 2, you can customize CMS Page or Block. Magento merchants can add customer names to provide a personalized experience to customers. Let’s start learning How to Add Customer Name in CMS Page/Block in Magento 2.
## Steps to Add Customer Name in CMS Page/Block in Magento 2:
**Step 1:** Create one block file on your custom extension at the below path:
**app\code\Vendor\Extension\Block\Customerinfo.php**

```
<?php
namespace VendorExtensionBlock

class Customerinfo  extends MagentoFrameworkViewElementTemplate
{
     protected $_session;

      public function __construct(MagentoCustomerModelSession $session)
      {
           ...
           $this->_session = $session;
           ...
      }

      public function getCurrentCustomernameinfo()
      {
           if ($this->_session->isLoggedIn())
           {
                return $this->_session->getCustomer()->getName();
           }
      }
}
```

[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2023/10/Magento-2-Speed-Performance-Optimization-Services-CTA-4.webp)](https://magecomp.com/magento-performance-optimization.html)

**Step 2:** Now create a phtml file in the below path
**app\code\Vendor\Extension\view\frontend\templates\mycustomfile.phtml**

```
<?php echo $block->getCurrentCustomernameinfo(); ?>
```

Now call this phtml file into your CMS Block or CMS Page.
```
{{block class="VendorExtensionBlockCustomerinfo" template="mycustomfile.phtml"}}
```

## Conclusion:
This way you can Add Customer Name in CMS Page/Block in Magento 2. For any hardships with the execution of the above code, write to me in the comment part below. Do share the article amongst your Magento colleagues. Stay tuned for more such Magento solutions.
[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-4.webp)](https://magecomp.com/services/hyva-theme-development/)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/add-customer-name-in-cms-page-block-in-magento-2/](https://magecomp.com/blog/add-customer-name-in-cms-page-block-in-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-09-13 15:45:34 UTC_  
