Hello Magento Friends,

In today’s blog, I am going to show How to Remove a Block from Any Page using Observer in Magento 2.

Blocks are used to display pieces of content placed anywhere on the page. Blocks contain text, image or video. Blocks can be added and removed anytime when required. Usually while adding or removing blocks, you need to modify the layout XML file. But sometimes users need to remove the block without modifying the layout file.

Let’s learn How to Remove Block using Observer in Magento 2.

Steps to Remove Block from Any Page using Observer in Magento 2

Step 1:  We need to create an “events.xml” file inside our extension at the following path

app\code\Vendor\Extension\etc\

Then add the code as follows

Step 2:  After that, we need to create a “Removeblock.php” file inside our extension at the following path.

app\code\Vendor\Extension\Observer\

Now, append the below code

Conclusion:

This way you can easily Remove Block from Any Page using Observer in Magento 2. Also checkout, How to Remove Blocks From Layout Magento 2.

If you have any doubt regarding the above-mentioned steps, connect with me through the comment section. Share the article with your Magento colleagues and stay in touch with us

Happy Reading!

Click to rate this post!
[Total: 3 Average: 5]