How to Remove Elements via XML in Magento 2
- October 22, 2024
- Category: Magento 2
In Magento 2, you can remove specific elements like blocks or containers from a page layout by editing XML Files. This guide will walk you through how to do it.
Removing Elements via XML
To remove an element, you use the <referenceBlock> or <referenceContainer> tag with the remove attribute set to “true”.
Step-by-Step Example: Removing the Wishlist Link and Logo from the Header
Step 1: Create or edit the XML layout file:
To modify the page layout, create or edit the default.xml file located in your theme’s directory:
app/design/frontend/Vendor/Theme_name/Magento_Theme/layout/default.xml
Step 2: Add the Code
Add the following XML code to the default.xml file:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="authorization-link" remove="true"/>
<referenceBlock name="logo" remove="true" />
</body>
</page>
This will remove the wishlist link and the logo from the header.
Step 3: Clear the Cache
After making changes, clear the Magento cache by running the following command in your terminal
Php bin/magento cache:flush
Take Control of Your Magento 2 Layout Today! 💻
Ready to customize your online store’s look? With just a few simple XML tweaks, you can remove unwanted elements like the wishlist link and logo, enhancing your site’s user experience. Follow this guide, make your changes, and clear your cache to see your updates live!
Start customizing now and elevate your Magento 2 store to the next level!
Need assistance or have questions? Contact us today for Expert Support and personalized solutions!