Back to Top

Get All Product Images (Hidden & Disabled) in Magento 2

Updated 16 September 2025

Sometimes, product images are hidden or disabled in admin, yet you still want to access them.
For example, you may build a custom gallery or preview images before enabling them for customers.

Moreover, using only getMediaGalleryImages() shows only visible images.
Therefore, to get full control, you need methods that include disabled or hidden entries.

You can get the details of products images like filename, media_type, position, disabled and types.

Core Magento APIs to use

Magento provides ProductRepositoryInterface::getById() to load product data.

Searching for an experienced
Magento Company ?
Find out More

Then getMediaGalleryEntries() gives you all images, with metadata like disabled flag and position.

Additionally, Adobe explains the media gallery component in its official documentation for deeper reference.

Also, make sure you import MediaGalleryEntries via product interface.
You’ll need dependency injection for ProductRepository and necessary interfaces.

<?php
namespace Webkul\Test\Block\Image;

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Catalog\Api\ProductRepositoryInterface;

class Images extends Template
{
    /**
     * @var ProductRepositoryInterface
     */
    private $productRepository;

    public function __construct(
        Context $context,
        ProductRepositoryInterface $productRepository,
        array $data = []
    ) {
        $this->productRepository = $productRepository;
        parent::__construct($context,$data);
    }

    /**
     * get All images
     */
    public function getImages()
    {
        $productId = 1;
        $productDetails = $this->productRepository->getById($productId);
        $images = $productDetails->getMediaGalleryEntries();
        foreach ($images as $image) {
         echo "<pre>";print_r($image->getData());
        }
    }

This block fetches all images for a product by its ID.
It includes hidden and disabled images, which can be displayed as needed.

You will get the output

Array
(
    [file] => /w/s/wsh12-green_main_2.jpg
    [media_type] => image
    [entity_id] => 2046
    [label] => 
    [position] => 1
    [disabled] => 0
    [types] => Array
        (
            [0] => image
            [1] => small_image
            [2] => thumbnail
        )

    [id] => 3420
)
Array
(
    [file] => /w/s/wsh12-green_alt1_2.jpg
    [media_type] => image
    [entity_id] => 2046
    [label] => 
    [position] => 2
    [disabled] => 0
    [types] => Array
        (
        )

    [id] => 3421
)
Array
(
    [file] => /w/s/wsh12-green_back_2.jpg
    [media_type] => image
    [entity_id] => 2046
    [label] => 
    [position] => 3
    [disabled] => 0
    [types] => Array
        (
        )

    [id] => 3422
)

Rendering images in the template

In your .phtml file, call getImages($productId) to loop through the image array.
You can render <img> tags, show positions, or highlight disabled images for clarity.

This approach is particularly useful for admin previews or advanced galleries.
If you want to extend functionality further, consider Webkul’s Magento 2 Image Gallery Module for a feature-rich display.

Conclusion

In summary, using getMediaGalleryEntries() via ProductRepositoryInterface lets you fetch all images (hidden/disabled) for a product.
Meanwhile, using visible-only methods keeps public galleries simple.

By applying this logic appropriately, you get full flexibility and maintain clean display for customers.

That’s all

If any issue or doubt please feel free to mentioned in comment section.

I would be happy to help.

Happy Coding!!! 🙂

. . .

Leave a Comment

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


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home