How to Centralize Media Across WordPress Sites
When you manage multiple WordPress sites, and these sites have some shared content, you may be wondering if there is a way to prevent duplicating the same media files.
I mean, why copy an image from “Site 1” to “Site 2” when we can use it on “Site 2” by its direct URL from “Site 1”?
In this article, I am going to uncover different scenarios and how we can achieve the goal of having a centralized media library across WordPress sites, for example, when your sites are a part of a WP Multisite network, or when you’re using standalone sites.
Needless to say, all the methods described here work great for WooCommerce stores.
Scenario 1. Centralize Media in a WordPress Multisite Network
WordPress Multisite is a type of WordPress installation where you’re using a single folder on your server and a shared database for as many sub-sites as you want.
If you’re unsure whether your network of sites is actually a “Multisite network” or not, then most likely, it is not, and you need to jump to the second scenario. However, if your primary goal is to centralize media across WordPress sites, then, if possible, you need to merge your sites into a WordPress Multisite network.
Since the sites of a multisite network share the same WordPress folder on the server, there is also a shared wp-content/uploads folder, then using a centralized media library for all sites in a network makes perfect sense.
But how can we achieve that?
There is no checkbox in WordPress network settings or something like that, so the only solution here is to use a specific plugin for that.
My recommendation is to use the Multisite Shared Media Library plugin, which is regularly updated and fully supported by the latest WordPress version and most third-party plugins.
The first step is to network activate it from the Network Admin > Plugins page:

Then let’s configure the plugin in Network Admin > Settings > Network Media:

Here we can do two things:
- Choose which site will serve the purpose of a centralized media library.
- Choose the type of library (will the original one be replaced, or can we just have access to centralized media via the “Shared Media” tab).
Once you have finished configuring settings, that’s pretty much it. After that, either the media libraries of your sub-sites will be replaced with the central media library, or it will be available in a separate tab like this:

You can also exclude some specific sub-sites from having access to the network media library using the rudr_sml_network_library_allowed hook. For example:
add_filter( 'rudr_sml_network_library_allowed', function( $is_allowed, $blog_id ) {
if( 5 == $blog_id ) {
return false;
}
return $is_allowed;
}, 25, 2 );If you don’t know where to use this code snippet, check this guide.
Scenario 2. Using a Centralized Media Library for Standalone WordPress Sites
If your sites are not a part of a WordPress Multisite network and there is no way to merge them into it, then having a centralized media library will mean one of the two things:
- We can use one specific standalone WordPress site, which will also serve as a central media library. You can make changes to media files on that site, and all changes will be synced to the target sites. However, you will have image copies on every WordPress site in any case.
- You can offload media files to the cloud and have access to them from each site.
In this tutorial, we will mostly talk about the first way, because the second one involves using a third-party service or something.
2.1. Using media files from a centralized media library when syncing posts between sites
If your primary goal is to sync posts, pages, custom post types, or WooCommerce products between your WordPress sites, and syncing media files is just a secondary task that comes along with it, then using my Simple WP Crossposting plugin is your go-to choice here.
You simply need to connect WordPress sites in the plugin settings, and then you can select target sites when editing the content:

Speaking of WordPress media files, by the way, you will also need to activate their full synchronisation in the plugin settings, in Settings > Crosspost > Fields:

That’s pretty much it. Now, when you sync posts or WooCommerce products between connected WordPress sites, their media files will go along.
2.2 Syncing media files across WordPress sites
But what if you don’t need to sync the content (posts, WooCommerce products, or whatever), but you only need to sync media files between standalone WordPress sites?
At this moment, I don’t have a WordPress plugin that does exactly that; however, you can still achieve it with the help of Simple WP Crossposting and a small code snippet.
As a result, you will have custom bulk actions in the Media > Library page (but don’t forget to switch to the list view).

This is the code snippet you need to use:
// add bulk actions
add_filter( 'bulk_actions-upload', function( $bulk_actions ) {
// get all the sites added in Settings > Crosspost > Sites
$sites = Rudr_Simple_WP_Crosspost::get_allowed_blogs();
if( $sites ) {
foreach( $sites as $site ) {
$bulk_actions[ 'sync_to_' . Rudr_Simple_WP_Crosspost::get_blog_id( $site ) ] = "Sync to {$site[ 'name' ]}";
}
}
return $bulk_actions;
}, 25 );
// perform bulk action
add_filter( 'handle_bulk_actions-upload', function( $redirect, $doaction, $attachment_ids ) {
if( 'sync_to_' !== substr( $doaction, 0, 8 ) ) {
return $redirect;
}
// extract blog ID from bulk action
$site_id = str_replace( 'sync_to_', '', $doaction );
$site = Rudr_Simple_WP_Crosspost::get_blog( $site_id );
$count = 0;
foreach( $attachment_ids as $attachment_id ) {
$image = Rudr_Simple_WP_Crosspost::maybe_crosspost_image( $attachment_id, $site );
if( isset( $image[ 'id' ] ) && $image[ 'id' ] ) {
$count++;
}
}
$redirect = add_query_arg(
array(
'rudr_bulk_synced_media' => $count,
),
$redirect
);
return $redirect;
}, 25, 3 );
// print notices
add_action( 'admin_notices', function() {
if( ! empty( $_REQUEST[ 'rudr_bulk_synced_media' ] ) ) {
// depending on how many posts have been changed, our message may be different
printf(
'<div id="message" class="updated notice is-dismissible"><p>' . _n( '%d media file has been synced.', '%d media files have been synced.', absint( $_REQUEST[ 'rudr_bulk_synced_media' ] ) ) . '</p></div>',
$_REQUEST[ 'rudr_bulk_synced_media' ]
);
}
}, 25 );Is there any other way?
As I already mentioned before, you can use a cloud service to upload media files from your server (where your WordPress site is) to a cloud server. It will allow you to prevent having file duplicates across your WordPress sites; however, you will still need to sync media information in the database across your WordPress sites.
Misha Rudrastyh
Hey guys and welcome to my website. For more than 15 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me