🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Delete Product Attributes Programmatically in Magento

By Sanjay JethvaUpdated on May 22, 2025 1 min read

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 through a single Magento may mess up attributes on different scope levels. It happens due to the test products and its attributes created. A developer may want to clean the DB after the tests. It’s almost impossible to find and delete such attribute values from the admin panel and doing it manually takes time and effort. Instead, I’ve come up with a solution to delete product attributes programmatically in Magento.

When you delete an attribute, it is automatically removed from any related products and attribute sets.

Method to Delete Product Attributes Programmatically in Magento:

require_once 'app/Mage.php';
umask(0);
Mage::app();

$attr = 'whatsapp_share'; //attribute code to remove

$setup = Mage::getResourceModel('catalog/setup', 'core_setup');
try {
  $setup->startSetup();
  $setup->removeAttribute('catalog_product', $attr);
  $setup->endSetup();
  echo $attr . " attribute is removed";
} 
catch (Mage_Core_Exception $e) {
  print_r($e->getMessage());
}

Implement the above code to delete product attributes programmatically in Magento!

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.