{"id":223,"date":"2018-10-31T13:04:13","date_gmt":"2018-10-31T13:04:13","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2018\/10\/31\/delete-product-attributes-programmatically-in-magento\/"},"modified":"2025-05-22T17:15:09","modified_gmt":"2025-05-22T11:45:09","slug":"delete-product-attributes-programmatically-in-magento","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/delete-product-attributes-programmatically-in-magento\/","title":{"rendered":"How to Delete Product Attributes Programmatically in Magento"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Attributes are the building blocks of your product catalog and it illustrates the characteristics of a product.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes while handling multiple store views or websites through a single Magento may mess up attributes on different scope levels.&nbsp;It happens due to the test products and its attributes created. A developer may want to clean the DB after the tests. It&#8217;s almost impossible to find and delete such attribute values from the admin panel and doing it manually takes time and effort. Instead, I&#8217;ve come up with a solution to <strong>delete product attributes programmatically in Magento<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you delete an attribute, it is automatically removed from any related products and attribute sets.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Delete Product Attributes Programmatically in Magento:<\/h2>\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=\"\">require_once 'app\/Mage.php';\numask(0);\nMage::app();\n\n$attr = 'whatsapp_share'; \/\/attribute code to remove\n\n$setup = Mage::getResourceModel('catalog\/setup', 'core_setup');\ntry {\n  $setup->startSetup();\n  $setup->removeAttribute('catalog_product', $attr);\n  $setup->endSetup();\n  echo $attr . \" attribute is removed\";\n} \ncatch (Mage_Core_Exception $e) {\n  print_r($e->getMessage());\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Implement the above code to delete product attributes programmatically in Magento!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Attributes are the building blocks of your product catalog and it illustrates the characteristics of a product. Sometimes while handling multiple store views or websites&#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-223","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/223","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=223"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/223\/revisions"}],"predecessor-version":[{"id":15568,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/223\/revisions\/15568"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}