How to Change the message position in magento?

How to Change the message position in magento?

August 7, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to Change the message position in magento?

Changing Magento Message Position: A Comprehensive Guide for Developers

As a developer working on Magento projects, you might often find the need to customize the default message position—be it an error or success message—to better suit your project’s layout and user experience. By default, Magento displays these messages inside the wrapper or content area. However, sometimes you may want to show them at the top of the page.

In this post, we’ll guide you through the process of changing the message position in Magento using a combination of core file modifications and custom XML layouts. Let’s dive into the solution:

Understanding the Default Message Position

Magento uses the Mage_Core_Controller_Varien_Action class to set up messages for display. By default, it adds them to the messages block located within the page layout.

 public function getMessagesBlock()
 {
     if (null === $this->_messages) {
         $this->_messages = $this->getLayout()->createBlock('core/messages');
     }
     return $this->_messages;
 }

The core/messages block, defined in the messages.xml layout file, adds messages to the content area:

<block type="core/messages" name="global_messages" as="messages">
    <action method="setTemplate"><template>page/messages.phtml</template></action>
</block>

Changing the Message Position

To move the message block to the top of the page, we’ll need to modify the core layout file and create a new XML layout update.

Step 1: Modify the Core Layout File

Open the app/design/frontend/base/default/layout/page.xml file. Locate the <block> element containing the core/messages block:

<block type="core/messages" name="global_messages" as="messages">
    <action method="setTemplate"><template>page/messages.phtml</template></action>
</block>

Change its position to top of the page by adding it inside the <reference name="head"> block:

<reference name="head">
    <block type="core/messages" name="global_messages" as="messages">
        <action method="setTemplate"><template>page/messages.phtml</template></action>
    </block>
</reference>

Step 2: Create a Custom XML Layout Update

While the above modification will work, it’s generally better to use a custom layout update file to avoid direct modifications to core files. This approach ensures your changes survive Magento updates and keeps your codebase cleaner.

Create a new file local.xml in your theme directory at app/design/frontend/[Your_Theme]/layout/local.xml. Add the following content:

<layout version="0.1.0">
    <default>
        <reference name="head">
            <block type="core/messages" name="global_messages" as="messages">
                <action method="setTemplate"><template>page/messages.phtml</template></action>
            </block>
        </reference>
    </default>
</layout>

Conclusion

In this post, we’ve demonstrated how to change the message position in Magento by modifying the core layout file or using a custom XML layout update. This technique provides you with greater control over your site’s UI and allows for better integration of messages with your project’s design.

Remember, always use a staging environment first when making changes to live production sites. If you’re not comfortable working directly with Magento’s core files, consider hiring an experienced developer or consulting the professional services offered by Laravel Company.

With this knowledge, you should now be able to easily customize the message position in your Magento projects. Happy coding!

Themes Errors

Our network