---
title: "How to Remove Product Attribute Programmatically in Magento 2"
url: "https://magecomp.com/blog/remove-product-attribute-programmatically-magento-2/"
date: "2020-06-09T17:51:30+00:00"
modified: "2025-02-20T08:55:33+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "General"
  - "Magento 2"
word_count: 321
reading_time: "2 min read"
summary: "Hello Magento Folks,"
description: "Remove the product attributes that got mixed up due to multiple website handling. Learn How to Remove Product Attribute Programmatically in Magento 2 here."
keywords: "General, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Get Active Shipping Methods based on Quote ID in Magento 2?"
    url: "https://magecomp.com/blog/get-active-shipping-methods-based-on-quote-id-magento-2/"
  - title: "How to Set Developer mode in Magento 2 (Included All Modes)"
    url: "https://magecomp.com/blog/set-developer-mode-magento-2/"
  - title: "Upgrade Magento 2 with Composer"
    url: "https://magecomp.com/blog/upgrade-magento-2-composer/"
---

# How to Remove Product Attribute Programmatically in Magento 2

_Published: June 9, 2020_  
_Author: Dhiren Vasoya_  

![How to Delete Product Attributes Programmatically In Magento 2](https://magecomp.com/blog/wp-content/uploads/2020/06/How-to-Delete-Product-Attributes-Programmatically-In-Magento-2-1024x512.webp)

Hello Magento Folks,
What’s up Magento freaks? Welcome to the [**Magento Tutorial blog series**](https://magecomp.com/blog/category/magento-tutorials/). All in one solution blog for all the Magento problems. As always let’s bind with our today’s topic where I am going to illustrate How to Remove Product Attribute Programmatically in Magento 2. Do check our previously placed article **[How To Hide Add To Cart Button in Magento 2](https://magecomp.com/blog/hide-add-to-cart-button-in-magento-2/)****.** Let’s Dive In.
[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-1.webp)](https://magecomp.com/services/magento-upgrade-services/)

## Introduction:
Mainly, in Magneto 2 the attributes are basically the building blocks of the product catalog that is specified as the characteristics of that product. Many times when there is a scenario of more than one website being handled then it might screw up attributes on different scope levels. Here, the developer might get stuck and confused over here therefore solving the problem with the below-given illustration.
## Steps to Remove Product Attribute Programmatically in Magento 2:
**Step 1:** Create InstallData.php at the following path and paste the below code.
**app\\code\\Vendor\\Extension\\Setup\\InstallData.php**

```
<?php
 namespace Vendor\Extension\Setup;

 use Magento\Eav\Setup\EavSetup;
 use Magento\Eav\Setup\EavSetupFactory;
 use Magento\Framework\Setup\InstallDataInterface;
 use Magento\Framework\Setup\ModuleContextInterface;
 use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface
 {
     private $eavSetupFactory;

     public function __construct(EavSetupFactory $eavSetupFactory)
     {
         $this->eavSetupFactory = $eavSetupFactory;
     }

     public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
     {
         $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
         $eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY,
         'custom_attribute_id');
     }
 }
```

[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-3.webp)](https://magecomp.com/magento-malware-removal.html)

**Step 2:** Refresh the cache and deploy the static content command.
```
php bin/magento cache:flush
php bin/magento setup:upgrade
```

```
php bin/magento setup:static-content:deploy -f
```

That’s It you will be quickly able to Remove Product Attribute Programmatically in Magento 2.
## Final Words:
Hopefully, all are able to solve the problem caused by removing Product Attribute Programmatically in Magento 2. In case any obstacles do contact our **[support team](https://magecomp.com/support/)** for more guidance. Do share with your Magento developer friends and comment down your reviews in the comment section below.
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-1.webp)](https://magecomp.com/magento-performance-optimization.html)

**Happy Coding.**


---

_View the original post at: [https://magecomp.com/blog/remove-product-attribute-programmatically-magento-2/](https://magecomp.com/blog/remove-product-attribute-programmatically-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-04-06 18:36:36 UTC_  
