i don’t know you are aware of it or not but in magento 1 We are able to remove block with
unsetBlock() method, but in Magento2 somehow it stopped working. So, i have found a way to remove block in Magento2 programmatically.
to do it we can Use
unsetElement() method to remove block. as like
$layout = $this->getLayout(); $block = $layout->getBlock('catalog.topnav'); // block name $layout->unsetElement('catalog.topnav');
hope this will help you.