magento 2 Element 'referenceContainer', attribute 'after': The attribute 'after' is not allowed

magento 2 Element 'referenceContainer', attribute 'after': The attribute 'after' is not allowed

July 13, 2026 · Illustrated author avatarBy Stefan Bogdanescu
magento 2 Element 'referenceContainer', attribute 'after': The attribute 'after' is not allowed

Solving “Element ‘referenceContainer’, attribute ‘after’: The attribute ‘after’ is not allowed” Error in Magento 2

Are you encountering the frustrating error message: “Element ‘referenceContainer’, attribute ‘after’: The attribute ‘after’ is not allowed”? This issue can suddenly appear without any apparent changes to your system. Let’s dive into understanding this problem and finding a solution.

Understanding the Error Message

The error occurs due to an invalid XML element in your Magento layout file. Specifically, it’s finding the referenceContainer element with the disallowed after attribute. This attribute is not recognized by the Magento 2 validation process for XML files.

Finding the Culprit: Locating the Problematic Layout File

To pinpoint the issue, you need to identify the layout file causing the problem. Here’s a step-by-step guide:

  1. Check the Error Log: The exception message includes a line number (e.g., Line 1251). This indicates where in your layout XML the issue is located.

  2. Locate the Layout File: Magento layout files are typically found under app/design/frontend/<Vendor>/<Theme>/layout. Look for the file mentioned in the error log or in the context of the error message (e.g., LAYOUT_frontend).

  3. Open the Relevant XML File: Open the identified layout file using your preferred text editor or IDE.

Removing the Disallowed “after” Attribute

Now that you have located the problematic layout file, it’s time to remove the offending after attribute from the referenceContainer element.

Here’s an example of what the issue might look like:

<referenceContainer name="content">
    <block type="cms/block" name="block1" after="-">
        <action method="setBlockId">
            <argument name="block_id" xsi:type="string">about_us</argument>
        </action>
    </block>
</referenceContainer>

To resolve the error, simply remove or comment out the after attribute:

<referenceContainer name="content">
    <!--
    <block type="cms/block" name="block1" after="-">
        <action method="setBlockId">
            <argument name="block_id" xsi:type="string">about_us</argument>
        </action>
    </block>
    -->
    <block type="cms/block" name="block1">
        <action method="setBlockId">
            <argument name="block_id" xsi:type="string">about_us</argument>
        </action>
    </block>
</referenceContainer>

Ensure that the layout file still maintains its intended functionality after removing the after attribute.

Conclusion

Investigating and resolving this error requires a structured approach:

  • Identify the specific layout file mentioned in the error log.
  • Locate the referenceContainer element with the disallowed after attribute.
  • Remove or comment out the after attribute to resolve the validation issue.

Remember, it’s crucial to backup your files before making any changes. If you’re unsure about modifying XML files directly, consider consulting a Magento 2 developer or reaching out to Laravel Company for professional assistance in troubleshooting and maintaining your e-commerce site.

Magento 2 Themes Errors

Our network