Prevent images from being imported into my website

This tutorial explains how to prevent images from being imported into your website's Media Library. This can be useful if you have a lot of products and don't want to fill up your site's storage.

IMPORTANT - It's important to remember that this technique will serve the images directly from the merchants server. If the merchant's images are not HTTPS, they may not display on your site. Also, you can not take advantage of using the img srcset attribute causing large images to be loaded on mobile devices.

First, you need to make sure you have the Custom Code plugin installed and activated. Learn more here.

Then add the following code to your Custom Plugin:

add_filter( 'dfrps_do_import_product_thumbnail/do_import', function ( bool $do_import, WP_Post $post, array $product ) {
   return new WP_Error(
         'Image import disabled by "%s" filter in "%s" for Post ID: %d',
         esc_html( current_filter() ),
         esc_html( basename( __FILE__ ) ),
         absint( $post->ID )
}, 10, 3 );

Next, add this code to your custom plugin.

Save your change. 

Now, when new products are imported into your site, their images will not be imported.

NOTE - Previously imported images will not be removed from your site and will still be displayed alongside your images which are displayed from external URLs.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us