I have a requirement like below.

I have uploaded a placeholder images for "Base Image", "Small Image" and "Thumbnail Image" in admin settings.

So whenever there is no product image is available, Magento gets this image and show in front end.

Here I need to change the functionality Instead of loading image from Placeholder path, Can we load from the Theme file image folder?

I have created a custom theme by extending Luma,

Inside Theme frontend/web/images/placeholder.png I have moved the Image file.

How can I change/modify the code where placeholder image reads the file from my theme path instead of default placeholder image path.

How this can be done? Any suggestions please.


You can create after plugin for that and replace placeholder URL:

Create di.xml file :

app/code/RH/Helloworld/etc/frontend/di.xml :

<?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="Magento\Catalog\Model\View\Asset\Placeholder">
        <plugin name="Custom_Block" type="RH\Helloworld\Plugin\Placeholder" sortOrder="110"/>

Create plugin file :



namespace RH\Helloworld\Plugin;

class Placeholder {

     * @param \Magento\Catalog\Model\View\Asset\Placeholder $subject
     * @param $result
     * @return string
    public function afterGetUrl(
        \Magento\Catalog\Model\View\Asset\Placeholder $subject, $result
    ) {
        $result = "test.jpg"; // Add your image full path which you want to display
        return $result;
  • Thanks Rohan..Working Great!!! – jafar pinjar Nov 26 '19 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.