How can I reference external attachments without breaking core WordPress files?
I am developing a site that uses WooCommerce WordPress to show a fair amount (10,000+) products, and can't accommodate the size of all the images for the products. So, I'm leaving the images on their CDN, and making all the image attachments references to the external URLs.
This required a bit of hacking, as WooCommerce/WordPress will try to take the images and upload them and set the attachment URL to a local relative path (eg, 2018/02/
), and then when the images are called later on the site, the wp_get_attachment_url
will add the uploads directory to the base image, giving something like site.com/wp-content/uploads/2018/02/whatever.jpg
.
Basically what I've done to make this all pan out is
- Stop WordPress from running the
wp_generate_attachment_metadata
by setting it toreturn true
as soon as the function is called, which prevents the image from being downloaded and from being copied into the uploads directory. - Upload the products from a CSV
- Run a MySQL query to copy the woocommerce source image URL on to the attachment location
- Override
wp_get_attachment_url
to not append the uploads directory to attachment images
Essentially, a couple of 1 line changes to the WordPress core. Which is bad, because any time in the future when the site updates it'll just bork the changes.
Is there a healthier way to approach this?
Topic woocommerce-offtopic core-modifications hacks csv Wordpress
Category Web