How to override magento default welcome message?

How to override magento default welcome message?

September 7, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to override magento default welcome message?

Overriding Magento Default Welcome Message: A Step-by-Step Guide

Hello everyone! Today, we’re going to tackle a common issue that many developers face when working on customizations in Magento - how to override the default welcome message.

Understanding the Current Code Structure

Rupak has provided us with an excellent starting point. Let’s break down his folder structure and code:

  1. Folder Structure: Rupak has created the necessary namespace (ChangeWelcome) and module (Page) folders under app/code/local/.

  2. config.xml: This file contains the configuration for the custom module. It specifies that we want to rewrite the Mage_Page_Block_Html_Header class.

  3. ChangeWelcome/Page/Block/Html/Header.php: This is where Rupak has created a new class, extending the original Mage_Page_Block_Html_Header. He’s defined a custom method called getWelcome() that should override the default welcome message.

  4. app/etc/modules/ChangeWelcome_Page.xml: This file activates the newly created module in the local code pool.

The Current Issue and Why It’s Not Working

Rupak has done everything correctly so far, but he’s facing a common pitfall with Magento’s block rewriting system. The issue lies in how Magento handles layout updates for custom blocks.

The rewrite configuration in Rupak’s config.xml is targeting the wrong block reference. He needs to target the specific block that contains the welcome message logic rather than the entire header block.

The Correct Approach: Overriding the Welcome Message Block

To fix this issue, we need to follow these steps:

  1. Identify the correct block: In Magento 2, the welcome message is rendered by the Magento_Theme\Block\Html\Header block in the layout file vendor/magento/module-theme/view/frontend/layout/default.xml.

  2. Rewrite the necessary block: Instead of rewriting the entire header block as Rupak did, we need to target this specific block.

  3. Create a new class: In Rupak’s custom module folder (in his case, under app/code/local/ChangeWelcome/Page/Block/Html/), create a new PHP file called Magento_Theme_Html_Header.php.

  4. Extend the original class: Write a new class that extends Magento\Theme\Block\Html\Header and override the necessary methods or properties.

  5. Update the configuration XML: In the config.xml file, update the rewrite configuration to target the Magento_Theme_Html_Header block specifically.

An Example of the Correct Implementation

Here’s an example of how Rupak should modify his code:

<!-- Updated config.xml -->
<config>
    <modules>
        <ChangeWelcome_Page>
            <version>0.1.0</version>
        </ChangeWelcome_Page>
    </modules>
    <global>
        <page>
            <block>
                <html>
                    <rewrite>
                        <item name="Magento_Theme_Html_Header" type="ChangeWelcome\Page\Block\Html\Magento_Theme_Html_Header" />
                    </rewrite>
                </html>
            </block>
        </page>
    </global>
</config>
<!-- app/code/local/ChangeWelcome/Page/Block/Html/Magento_Theme_Html_Header.php -->
class ChangeWelcome_Page_Block_Html_Magento_Theme_Html_Header extends Magento\Theme\Block\Html\Header
{
    public function getWelcomeMessage()
    {
        return "Ok------------1";
    }
}

Conclusion and Next Steps

In conclusion, to override the default welcome message in Magento 2:

  • Target the correct block (Magento_Theme_Html_Header) for rewriting.
  • Create a new class extending Magento\Theme\Block\Html\Header.
  • Override the necessary methods or properties.

By following this approach, you should be able to successfully override the default welcome message without encountering any layout issues. Remember to clear your Magento cache and refresh your frontend after making these changes.

If you’re looking for more in-depth guides on Magento development, make sure to check out our blog at Laravel Company. We regularly publish articles on best practices, tips & tricks, and common issues faced by developers working with Magento.

Happy coding! Let me know if you have any other questions.

Extensions Themes Configuration Errors

Our network