---
title: "Steps to Add Product Image ALT Text to All Product Images in Magento 2"
url: "https://magecomp.com/blog/set-product-name-as-default-alt-text-to-product-images-magento-2/"
date: "2022-07-18T17:02:18+00:00"
modified: "2025-02-19T05:31:38+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 385
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "If the alt text does not exists, you can set Product name as default alt text to all product images in Magento 2. Learn more"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Leverage Instagram for Magento Store"
    url: "https://magecomp.com/blog/leverage-instagram-for-magento-store/"
  - title: "How to Add File in Shopify Store using Laravel?"
    url: "https://magecomp.com/blog/add-file-in-shopify-store-using-laravel/"
  - title: "Top 5 Best CDN Providers for Magento 2 "
    url: "https://magecomp.com/blog/cdn-providers-magento-2/"
---

# Steps to Add Product Image ALT Text to All Product Images in Magento 2

_Published: July 18, 2022_  
_Author: Dhiren Vasoya_  

![How to Set Product Name as Default Alt Text to All Product Images in Magento 2](https://magecomp.com/blog/wp-content/uploads/2022/07/How-to-Set-Product-Name-as-Default-Alt-Text-to-All-Product-Images-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

Today I will be explaining How to Set Product Name as Default Alt Text to All Product Images in Magento 2.
Alt text for product images informs the search engine what the image is about and helps index the product image when the user fires a query related to it. For Magento 2 stores, it is essential to give alt text to all the product images to aid in search engine rankings. Large stores can take advantage of [**Magento 2 Image Alt Tags Extension**](https://magecomp.com/magento-2-image-alt-tags.html) to automate the product image alternate text process and save time.
[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-2.webp)](https://magecomp.com/services/hyva-theme-development/)

You can also set the product image ALT tags in Magento 2 for all the product images. To do that, follow the below-given steps.
## Steps to Set Product Name as Default Alt Text to All Product Images in Magento 2:
**Step 1:** First, we need to create a “di.xml” file inside our extension at the following path
**app\code\Vendor\Extension\etc\frontend**

Then add the code as follows
```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="MagentoCatalogBlockProductViewGallery">
	<plugin name="alt_text_plugin" type="VendorExtensionBlockProductViewGalleryPlugin" sortOrder="10" />
    </type>
</config>
```

**Step 2:** After that, we need to create a **“ Plugin .php”** file inside extension Controller directory
**app\code\Vendor\Extension\Block\Product\View\Gallery\**

Now add the code as mentioned below
```
<?php
namespace VendorExtensionBlockProductViewGallery;

use VendorExtensionHelperData;
use MagentoCatalogModelLayerResolver;
class Plugin
{
    public function afterGetGalleryImages($block, $images)
    {
        try
        {
            $product = $block->getProduct();
            $name=$product->getName();

            foreach ($images as $image) {
                    $image->setLabel($name);
            }
        }
        catch (Exception $e)
        {
            MagentoFrameworkAppObjectManager::getInstance()->get('PsrLogLoggerInterface')->info($e->getMessage());
        }
        return $images;
    }
}
```

## [![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2-2.webp)](https://magecomp.com/services/magento-upgrade-services/)

## Conclusion:
This way you can easily Set Product Name as Default Alt Text to All Product Images in Magento 2. If you have any doubts about the above steps, freely share with me via the comment part. I will definitely solve your problem. Share the tutorial with your friends and stay in touch for more solutions.
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-2.webp)](https://magecomp.com/magento-performance-optimization.html)

Also, check [Magento 2 WebP Image Converter](https://magecomp.com/magento-2-webp-image-converter.html) Extension to automatically convert your image to webp image.

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/set-product-name-as-default-alt-text-to-product-images-magento-2/](https://magecomp.com/blog/set-product-name-as-default-alt-text-to-product-images-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-10-13 09:04:49 UTC_  
