How To Override Product NewWidget Block in Magento 2

Magento 2 recommends not to edit the default core files as you may lose your customizations when upgrading to the latest Magento 2 version. The better solution to this issue is to modify the core functionality by overriding the core files, classes, blocks, and methods to serve this purpose.

Sometimes it requires placing the related template file into the override block with the same directory path as the original when we override the widget block class.

Follow this method to override product NewWidget block in Magento 2 when you want to modify new widget block class.

Method to Override Product NewWidget Block in Magento 2

    1. Create di.xml file at app/code/Vendor/Module/etc into the custom module.
    2. Create a block file NewWidget.php at app/code/Vendor/Module/Block/Product/Widget to extend the widget class.

Do consider while using preference that another module has not used the same preference in the di.xml file.

That’s it!

If you have any doubts in the above solution, just mention them in the Comments section below.

I would be happy to help.

Feel free to share the solution with Magento Community via social media.

Thank You.

(based on 12 Reviews)
How To Override Product NewWidget Block in Magento 2Author Magento Badge

Sanjay Jethva

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.


  • vipul

    I have tried your solution but its now working, I am getting error Error filtering template: Invalid template file: ‘product/widget/new/content/new_grid.phtml’ in module block’s name: ‘product\widget\newwidget_0’

    • Sanjay Jethva

      Hello Vipul,
      Use the below code:

      Create new_grid.phtml file at:
      Thank You.

Leave a Reply

Your email address will not be published.