Categories: How ToMagento 2

How to Add Custom Image Attribute in Magento 2 Categories

During Magento customization, many of our clients request to extend the default functionality of Magento 2 categories. Recently one of them asked to add custom image attribute in category of Magento 2. To fulfill the requirement, I develop below code which I would like to share with you.

You need to add custom image attribute in the following files:

app/code/Vendor/Categoryattribute/Setup/ UpgradeData.php

First of all we need to add the attribute with proper parameters. Use code below:


If you have properly followed the code, image attribute would have been added to category in Magento 2 category.
Now once we have created the attribute, we need to save it in backend. Use following code:


Hope you followed the code properly and could create custom image attribute. If you are stuck between somewhere, I’m always there to provide you with solution. Comment your queries and suggestions.

Enjoy Coding!

Click to rate this post!
[Total: 12 Average: 4.3]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

View Comments

  • Hello

    Where we can add "Vendor\Categoryattribute\CategoryThumbUpload" and can you please give me the example that file

  • I can not find where the field is added, what "general" section do you mean? I can not see a section with that name
    Thanks

  • I disappointed. Why did you post code that doesn't work?
    I see new attribute in eav_attribute table but I doesn't see in admin panel.

  • Hi,

    There is no General information tab is available in Magento 2 Categories section?

    So where added category attribute shown by using above code?

    • The attribute should be available in "General" section, if you followed all the steps and executed it successfully.

  • Hello,

    Can you please tell me where we can add below code. Please give me file location.

    <?php
    namespace Vendor\Categoryattribute\Model\Category\Attribute\Backend;
    .............

    • You need to create file at following location
      app/code/Vendor\Categoryattribute\Model\Category\Attribute\Backend\Thumb.php and put the given code there.

  • Hi!

    Thanks for a great article!

    Is it possible to modify the code a bit in order to add custom file upload attribute to Products in Magento2? I want to be able to upload product sheets to products in Magento2.

    Thanks in advance!

    • This tutorial is about adding custom image attribute in categories and not in products. To get the solution for adding image attribute in products, Contact us and we will be happy to help you further.

Recent Posts

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

2 days ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

4 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

4 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

5 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

6 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

1 week ago