---
title: "How to Remove Block from Any Page using Observer in Magento 2"
url: "https://magecomp.com/blog/remove-block-using-observer-magento-2/"
date: "2022-06-06T16:09:46+00:00"
modified: "2025-02-17T07:00:56+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 319
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "Delete any block with the help of an observer instead of modifying the layout file in Magento 2. Learn more"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Reindex Specific Products Programmatically in Magento 2?"
    url: "https://magecomp.com/blog/reindex-specific-products-programmatically-magento-2/"
  - title: "How to Update Product Attribute using Data Patch in Magento 2?"
    url: "https://magecomp.com/blog/update-product-attribute-using-data-patch-magento-2/"
  - title: "Magento 2 Developer Beta"
    url: "https://magecomp.com/blog/magento-2-developer-beta/"
---

# How to Remove Block from Any Page using Observer in Magento 2

_Published: June 6, 2022_  
_Author: Dhiren Vasoya_  

![How to Remove Block from Any Page using Observer in Magento 2](https://magecomp.com/blog/wp-content/uploads/2022/06/How-to-Remove-Block-from-Any-Page-using-Observer-in-Magento-2-1024x512.webp)

**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.
[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-3.webp)](https://magecomp.com/services/hyva-theme-development/)

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
```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="layout_generate_blocks_after">
        <observer name="removeblock" instance="VendorExtensionObserverRemoveblock" shared="false" />
    </event>
</config>
```

**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
```
<?php
namespace VendorExtensionObserver;

use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;

class Removeblock implements MagentoFrameworkEventObserverInterface
{
    public function execute(MagentoFrameworkEventObserver $observer)
    {
        $layout = $observer->getLayout();
        $your_condition = 1; // write your conditional logic here
        if($your_condition == 1)
        {
                // you need to modifed block name as per your requirement.
                $layout->unsetElement('customer-account-navigation-orders-link');
        }
    }
}
```

## [![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-3.webp)](https://magecomp.com/services/hire-magento-programmer/)

## 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**](https://magecomp.com/blog/remove-blocks-or-containers-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
[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2.webp)](https://magecomp.com/services/magento-upgrade-services/)

**Happy Reading!**


---

_View the original post at: [https://magecomp.com/blog/remove-block-using-observer-magento-2/](https://magecomp.com/blog/remove-block-using-observer-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-09 00:58:42 UTC_  
