How to Add Custom Image Attribute in Magento 2 Categories

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!

Previous Article

How to Redirect to a Particular Page After Login in Magento 2

Next Article

How to Add WYSIWYG Editor in Magento 2 Admin Form

Write a Comment
  1. 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!

    1. 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.

  2. 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;
    ………….

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

  3. Hi,

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

    So where added category attribute shown by using above code?

  4. 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.

  5. 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

  6. Hello

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

Leave a Comment

Your email address will not be published. Required fields are marked *

Get Connect With Us

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨