How to Disable Newsletter Popup Manually

To disable the Magento 2 Newsletter popup manually, you need to add this code to XML layout:

<referenceBlock name="newsletter.popup">
    <action method="disable" />
</referenceBlock>

Code Example

<body>
        <referenceContainer name="root">
            <referenceBlock name="newsletter.popup">
                <action method="disable" />
            </referenceBlock>
            ....
        </referenceContainer>
    </body>

In order to disable Newsletter Popup Extension using controller class, please use the following code:

$newsletterBlock = $this->_view->loadLayout()->getLayout()->getBlock('newsletter.popup');
if ($newsletterBlock) {
    $newsletterBlock->disable();
}

Code Example

namespace MagentoContactControllerIndex;
    
    class Index extends MagentoContactControllerIndex
    {
         public function execute()
         {
              $this->_view->loadLayout();
              $newsletterBlock = $this->_view->loadLayout()->getLayout()
                  ->getBlock('newsletter.popup');
    
             if ($newsletterBlock) {
                 $newsletterBlock->disable();
             }
    
             $this->_view->renderLayout();
         }
    }

Was this article helpful?