Get the Product Image Placeholder URL

Do you need to get the product image placeholder url and you do not know how? Let's see how you can easily get it!

As is well known, in Magento admin you can define the product image placeholder url under

Stores- > Configuration -> Catalog -> Catalog -> Product Image Placeholders

and also for different image sizes, like base, small, thumbnail, etc.

The function that you have to use is the public function getDefaultPlaceholderUrl of the Magento\Catalog\Helper\Image class. which it takes as parameter the $placeholder type.

So using just for our example the object manager you can get it like:

$imageHelper = \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Catalog\Helper\Image::class);

$imageHelper->getDefaultPlaceholderUrl('image');

$imageHelper->getDefaultPlaceholderUrl('small_image');

$imageHelper->getDefaultPlaceholderUrl('thumbnail');

$imageHelper->getDefaultPlaceholderUrl('swatch_image');

Feel free to share this post and ask your questions in the comments below.

Till next time!

DigitalOcean Referral Badge