1

I want to change page title of My Account Page only like below:

welcome back, Customer.firstname()

How I can change my account page title only with customer firstname?

2

You can do this by pluginize exceute method. Try following way:

  1. Create plugin[Vendor/Module/etc/frontend/di.xml]

<?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\Controller\Account\Index">
        <plugin name="Vendor_Module::my_account" type="Vendor\Module\Plugin\Customer\Controller\Account\Index" sortOrder="10"/>
    </type>
</config>
  1. Now create class [Vendor/Module/Plugin/Customer/Controller/Account/Index.php]

namespace Vendor\Module\Plugin\Customer\Controller\Account;

class Index
{
    /**
     * @var \Magento\Customer\Model\Session
     */
    protected $customerSession;

    /**
     * @param \Magento\Customer\Model\Session $sessionSession
     */
    public function __construct(
        \Magento\Customer\Model\Session $sessionSession
    ) {
        $this->customerSession = $sessionSession;
    }

    public function afterExecute(
        \Magento\Customer\Controller\Account\Index $subject,
        $resultPage
    ) {
        $resultPage->getConfig()->getTitle()->set(__('Welcome back %1', $this->customerSession->getCustomer()->getName()));

        return $resultPage;
    }
}

Clear cache.

  • I have tried the above code, I have created the same files and directory structure in the app/code/MyVendor/Mymodule but it's not working. Please suggest if I am going wrong. – mageDev0688 May 5 '17 at 5:59
  • Sorry, I have just tried to format you answer with the color code. Please ignore it. – mageDev0688 May 5 '17 at 6:10
  • Did you create module? that means 'Vendor\Module'? – Sohel Rana May 5 '17 at 8:01
  • Check here ranasohel.me/2014/03/07/creating-a-custom-module-in-magento-2, after that follow this answer. – Sohel Rana May 5 '17 at 8:03
  • Verndor => your vendor name, Module => your module name, Got It? – Sohel Rana May 5 '17 at 8:04

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.