I need show success or error messages block at the top of the page before the header block. As of now it appears between the breadcrumbs and main block.

2 Answers 2


There are a couple of ways to do this. Here is one which requires a little layout xml and a new template at a minimum…


        <reference name="after_body_start">
            <block type="core/template" name="top.messages" template="core/messages/top.phtml" before="-" />

Template: app/design/frontend/your_package/your_theme/template/core/messages/top.phtml

<?php $_messageCollection = $this->getMessagesBlock()->getMessageCollection() ?>

<?php if ($_messageCollection->count()): ?>
        echo $this->getMessagesBlock()->getGroupedHtml();
<?php endif; ?>

Alternate way

add belwo line at app/design/frontend/your_package/your_theme/Magento_Theme/laout/default.xml

<page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

    <move element="page.messages" destination="after.body.start"  after="-"/>


  • why we need to create new phtml? its possible to move elements using XML right?
    – Sathish
    Dec 26, 2018 at 6:44
  • There are a couple of ways to do this. Dec 26, 2018 at 6:47
  • Updated answer. Dec 26, 2018 at 7:28
  • Thank you the alternate way method worked for me...
    – Shami
    Dec 27, 2018 at 4:28
<move element="page.messages" destination="after.body.start"  after="global_notices"/>

This will place it at the top of the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.