{"id":1566,"date":"2021-02-11T09:56:09","date_gmt":"2021-02-11T09:56:09","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/override-product-newwidget-block-in-magento-2\/"},"modified":"2025-09-01T11:46:26","modified_gmt":"2025-09-01T06:16:26","slug":"override-product-newwidget-block-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/override-product-newwidget-block-in-magento-2\/","title":{"rendered":"How To Override Product NewWidget Block in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2\u00a0recommends not to edit the default core files as you may lose your customizations when\u00a0<a href=\"https:\/\/meetanshi.com\/magento-upgrade-service\" target=\"_blank\" rel=\"noreferrer noopener\">upgrading to the latest Magento 2 <\/a><a href=\"https:\/\/meetanshi.com\/magento-upgrade-service.html\" target=\"_blank\" rel=\"noreferrer noopener\">version<\/a>. 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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Follow this method to&nbsp;<em><strong>o<\/strong><strong>verride product NewWidget block in Magento 2&nbsp;<\/strong><\/em>when you want to modify new widget block class.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Override Product NewWidget Block in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create&nbsp;<strong>di.xml<\/strong>&nbsp;file at&nbsp;<strong>app\/code\/Vendor\/Module\/etc&nbsp;<\/strong>into the custom module.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n        xsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager\/etc\/config.xsd\">\n    &lt;preference for=\"\\Magento\\Catalog\\Block\\Product\\Widget\\NewWidget\"\n              type=\"Vendor\\Module\\Block\\Product\\Widget\\NewWidget\"\/>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create a block file&nbsp;<strong>NewWidget<\/strong><em><strong>.<\/strong><\/em><strong>php<\/strong>&nbsp;at&nbsp;<strong>app\/code\/Vendor\/Module\/Block\/Product\/Widget<\/strong>&nbsp;to extend the widget class.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Vendor\\Module\\Block\\Product\\Widget;\nuse Magento\\Catalog\\Block\\Product\\Widget\\NewWidget;\nclass NewWidget extends NewWidget\n{\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Do consider while using preference that another module has not used the same preference in the di.xml file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it! Likewise you can also&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/override-product-view-page-social-meta-tags-in-magento-2\/\">override product view page social meta tags in Magento 2<\/a>, as a store owner it will help you to hide social meta tag or dynamically change content of social meta tags.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the solution with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2\u00a0recommends not to edit the default core files as you may lose your customizations when\u00a0upgrading to the latest Magento 2 version. The better solution&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1566","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1566"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1566\/revisions"}],"predecessor-version":[{"id":21407,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1566\/revisions\/21407"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}