Display external product image URLs instead of importing images into your 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.
This technique requires the use of the free version of the 3rd party Featured Image from URL (FIFU) plugin.
IMPORTANT - It's important to remember that this technique will serve the images directly from the merchants server. If the merchants' 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.
Steps
First: You need to make sure you have the Custom Code plugin installed and activated. Learn more here.
Second: 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 ) { /** * Use this line to specify specific merchants to use the FIFU plugin on. * You can get Merchant IDs here (in the MID column): https://datafeedr.me/networks * * If you want FIFU to be applied to all products in your store, don't change anything. * * Example Formatting: * $specific_merchant_ids = [ 12345, 67890, ]; */ $specific_merchant_ids = []; if ( ! isset( $product['image'] ) ) { return $do_import; } if ( ! function_exists( 'fifu_dev_set_image' ) ) { return $do_import; } if ( ! empty( $specific_merchant_ids ) ) { if ( ! in_array( absint( $product['merchant_id'] ), $specific_merchant_ids, true ) ) { return $do_import; } } fifu_dev_set_image( $post->ID, $product['image'] ); return new WP_Error( 'image_import_replaced_by_fifu_plugin', sprintf( 'Image import disabled by "%s" filter in "%s" for Post ID: %d', esc_html( current_filter() ), esc_html( basename( __FILE__ ) ), absint( $post->ID ) ) ); }, 11, 3 );
Third: Go here WordPress Admin Area > Plugins and install and activate the Featured Image from URL (FIFU) plugin.
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.