Magento - remove block using update XML

Magento - remove block using update XML

July 6, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento - remove block using update XML

Removing Blocks in Magento Using Layout XML Files

In this guide, we’ll dive into a common task in Magento development: removing an existing block from the layout using XML files. Specifically, we’re going to remove the “currency” block that’s currently being inserted into the “top.switches” block via the directory.xml file.

Understanding the Current Setup

Let’s first understand what we have right now:

  1. The default layout configuration contains a reference to the top.switches block.
  2. Inside this reference, there is a block element of type “directory/currency,” named “currency”, and set before the “store_language” block.
  3. This currency block uses the template “directory/currency.phtml”.
  4. Additionally, there’s another block “optional_zip_countries” referenced in the head section.

Our goal is to remove this specific “currency” block from the layout without affecting other elements or the overall theme structure.

Creating a Custom Layout XML File

The first step is to create a custom layout XML file where we’ll define our modifications. This approach keeps your changes separate from Magento’s core files, ensuring they don’t get overwritten during updates.

Create a new file named remove_currency_block.xml in the following directory:

app/design/frontend/{your_package}/{your_theme}/layout

Defining the Changes

Open this new XML file and add the following code:

<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layouts.xsd">
    <default>
        <reference name="top.switches">
            <remove name="currency"/>
        </reference>
    </default>
</layout>

Breaking Down the Code

  1. The <?xml version="1.0"?> line specifies the XML version.
  2. The <layout> element is the root container for our layout updates.
  3. Inside this, we define a new default scope, which applies to all pages unless overridden by more specific scopes.
  4. The <reference name="top.switches"> section targets the “top.switches” block specifically.
  5. Finally, the <remove name="currency"/> line instructs Magento to remove the “currency” block from this reference.

Configuring the Custom Layout XML

Now, we need to tell Magento to use our custom layout file instead of the core directory.xml for the currency block.

  1. Open your theme’s theme.xml file located at:
app/design/frontend/{your_package}/{your_theme}/etc/theme.xml
  1. Add or modify the <layout> section as follows:
<layout>
    <default>
        <reference name="directory_currency">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">{$block->getModuleDirectory('Magento_Directory')}/currency.phtml</argument>
            </action>
        </reference>
        <!-- Add this line -->
        <update handle="remove_currency_block"/>
    </default>
</layout>
  1. Save the theme.xml file.

Testing the Changes

Clear your cache and refresh your Magento site:

php bin/magento cache:clean
php bin/magento cache:flush

Navigate to a page where you expect to see the “currency” block, such as the header or top menu area. If everything is set up correctly, you should no longer see this specific currency switcher.

Conclusion

In this guide, we demonstrated how to remove an existing Magento block using layout XML files. This approach allows for cleaner code and easier maintenance compared to directly editing core files.

Remember that changing the layout requires a basic understanding of Magento’s architecture and how it processes layout XML files. If you’re unfamiliar with any part of the process, feel free to explore in-depth resources on Laravel Company for more detailed explanations.

As a final note, always ensure you have a backup before making significant changes to your live site’s codebase. This will protect your data and provide a safety net if anything goes wrong during the testing process.

Happy coding!

Themes Configuration Pricing

Our network