0

I have a client that has 3 sites. Two of them are retail and one of them is wholesale. They all carry the same products, so the majority of the media files are the same on all 3 sites. Two of the sites are subfolders of the 'main' site.

To save drive space and effort on my part, is it possible to have a single media library and have the 3 sites share it? Could i do this by setting the media directory of 2 of the sites to a soft link to the 3rd media directory?

A multisite set up will not work for me due to the tools i'm using.

I'm assuming that the media serialized data would mess that up, but has anyone tried this before?

4
  • Can you elaborate more? What do you mean by"Two of the sites are subfolders of the 'main' site"? Doesn't that imply a network setup with folders?
    – Greeso
    Jul 16, 2017 at 20:17
  • Also, to understand what you want. You like to upload images into one site, and then those images will be available to the other sites? Right?
    – Greeso
    Jul 16, 2017 at 20:18
  • @Greeso Right. peppersprayandstunguns.com is the main site in the wp directory. psproducts.com and personalsecurityproducts.net are in subfolders in peppersprayandstunguns directory structure. The sites all have the same products on them. So when they have a new stun gun or something, i have to upload the same new pictures for the item 3 times, as all 3 sites have the same product pictures. Having the same item pictures on all 3 sites means that 3x the disc space is taken up too, and if i had only one set of images the client's browser would cache better as well.
    – Bearcat
    Jul 16, 2017 at 20:31

2 Answers 2

0

Yes you can use Linux symlinks for your "slave" sites /uploads/ folders, and point those symlinks to your main site's /uploads/ directory and WordPress doesn't know the difference :)

The folder structure of your server doesn't matter, this solution works with all kinds of complex directory trees as long as your have the ability to add symlinks:

https://wordpress.stackexchange.com/a/408075/152624

You also should consider setting up a cron job to ensure the symlinks don't get overwritten.

2
  • 1
    In this instance, WP will still use just as much space but it will store all the files in the same folder, with 3 separate media libraries. If the same file is uploaded to a second install it will see the file already exists and either fail or create a version with -2 on the end
    – Tom J Nowell
    Jul 28, 2022 at 22:45
  • Thanks for the clarification @TomJNowell ... FYI to others, as discussed in the link you still need to figure out how to sync attachment metadata in the database (e.g. if you are trying to do staging sites or something like that) and/or like Tom says here, avoid uploading files with the same filenames. Aug 1, 2022 at 10:44
0

Reading your comment, I think I have an idea of what to do. I will explain that idea to you, but would not be able to show any code, because it is just an idea, never implemented it yet.

I would suggest that you setup your sites to lead images from Amazon AWS S3. And on each of your sites, you would install The WP Offload S3 Plugin, and link the media files from those sites to the images in S3, but to do this last bit (linking the images), you have to write a plugin yourself, that ensure the images ID's and references are accurate to all three sites.

I hope this makes sense. If this was me, this is how I would tackle this issue.

I think you can still do it without the S3, but you would still need to write some hooks that run whenever a media file is uploaded, so you update links to those images correctly.

That said, I think using S3 is more efficient in terms of pricing.

Anyway, this is just an idea, you have to do a bit of planning and investigation first. I think it would take a month or 6 weeks to finalize by one preson.

Good luck.

1
  • Be very careful using solutions like WP Offload... I have had many clients mess up their website big time because they didn't realize it deletes local files by default... IMO avoiding data loss should be the "default" setting for software. If you decide you don't want to use the plugin anymore it can become a massive project trying to fix your database and files back to the normal WordPress structure. Aug 1, 2022 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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