How to Manage Media Files in WordPress Multisite
In this tutorial, we will talk about ways of managing media files when you’re running a bunch of WordPress websites within a single WordPress multisite network. By the way, if you’re not 100% sure what a multisite network is, then you’re probably running multiple standalone sites.
Long story short, I will show you how the media files in multisite networks are handled by WordPress, how to set up centralized media management across your network, and also how to organize media with folders.
How Media Files Are Stored in WordPress Multisite
First of all, I want to remind you that media in WordPress are not only files on the server, but also a custom post type attachment which is stored in the database with all the necessary data.
| Files | Database |
|---|---|
All the files are getting landed in the uploads directory as usual; however, now they will be separated into folders uploads/sites/{id} where “id” is the ID of a subsite where this media was uploaded.For instance, for a subsite with ID = 7, the uploads folder will be /uploads/sites/7.What about the main site? Its media files will be uploaded directly to the uploads directory as usual, not to /sites/1. | Since media files are also a custom post type, it means that media information is stored in both wp_{id}_posts and wp_{id}_postmeta tables, where “id” is the ID of a subsite within a WordPress multisite network. For instance, if you upload an image to the subsite “7”, then its data will be added to wp_7_posts and wp_7_postmeta database tables. Of course, I am considering that you’re using the default wp_ prefix here, but it is not necessary. |
Each sub-site of the multisite network only has access to its own media files, so, by default, there is no way to access media files from the main site (or any other sub-site).
A programmatic way to use a shared uploads folder for all subsites within a network
In case you’re not happy with the moment, your media uploads are getting separated into /uploads/sites/2, /uploads/sites/3, etc. directories, you can use the code snippet below to make the /uploads directory itself shared across all sites in your WordPress multisite network.
add_filter( 'upload_dir', 'rudr_shared_uploads_folder', 25 );
function rudr_shared_uploads_folder( $uploads ) {
$uploads[ 'basedir' ] = ABSPATH . 'wp-content/uploads';
$uploads[ 'baseurl' ] = network_site_url() . '/wp-content/uploads';
return $uploads;
}If you don’t know how to use code snippets, you can check this guide; however, one more thing: the snippet should be network-activated.
What the snippet does is:
- Forces all future uploads into the shared
/uploadsdirectory. - If you’re using the
wp_upload_dir()somewhere on your website (I bet you are), it will point to the/uploadsdirectory now (it means that previous file uploads, which are currently inside/sites/{id}directories should be moved manually. - If you upload an
image.jpgfile from “Site 1”, and then you decide to upload an image with the same file name, the original image will be replaced.
Also, the snippet doesn’t provide you with the shared media management option. I mean, yes, the files now share the same uploads directory, but if you add a file from “Site 1”, you can only see this file in the admin dashboard of “Site 1”.
If you’re interested in a more sophisticated solution, please continue to the next chapter.
Using Global Media Library Plugin in WordPress Multisite
If you’re looking for more advanced multi-site media management in WordPress, then you’d probably need to consider using a plugin for that.
Below, I will show you two ways of setting up the centralized media library in your WordPress multisite network:
- The media library of a specific subsite of a multisite network is used as a shared media library across all sites. It means, when you try to add an image to posts on “Site 7” (for example), you can select the images directory from “Site 1”.
- Every subsite of a network has its own media library as usual; however, you have access to the shared media library in a separate tab.
An example of “Option 2” is on the screenshot below:

Both options can be achieved with the Multisite Shared Media Library plugin.
Choosing which subsite will be a centralized media library (optional)
This step is completely optional; however, if you’re sure that you want your “Site 7”, for example, to serve the purpose of the global media library, then you need to do this step at the very first moment after the plugin installation.
Can we change a subsite used as a centralized media library anytime? Yes, the images already used in posts will not become broken or anything; however, I do not recommend doing it to prevent you from getting lost in all these media files.
Now, straight to the point, by default, the plugin relies on the get_main_site_id() function to select which subsite should serve the purpose of the centralized library; usually it is a subsite whose ID is “1”. But you can change it in the plugin settings easily or with the help of the rudr_sml_network_library_id filter hook; let’s say we want to change it to “Site 7”, then the code snippet will be:
add_filter( 'rudr_sml_network_library_id', function( $centralized_library_id ) {
$centralized_library_id = 7;
return $centralized_library_id;
} );You can also find this filter hook in the plugin documentation.
Choosing whether to display a “Shared media” tab or fully replace local media libraries
Right now, I’m just diving a little bit deeper into the media library types I mentioned before.
Basically, we can just go to the plugin settings, Settings > Network Media, in the Network Dashboard, and do the configuration there:

For example, if I select the “Display shared media in a separate tab” option, then I will have the “Shared media” tab available on all subsites except the main site:

What about the uploads folder? Well, obviously, the uploads directory of a subsite, which is chosen as a centralized library, will be used. In other words, by default, it is going to be /uploads; however, if you changed it to “Site 7” here, then it is going to be /uploads/sites/7, but it can still be modified with the code snippet above.
More about setting up a centralized media library you can read in this tutorial.
Why is this plugin working without issues? (technical explanation)
If you have ever used other global media library plugins, you may know that when you start doing some basic things, like installing the “Twenty Twenty” default WordPress theme and setting a featured image there, it seems to be working. But once you go further with your site configuration, maybe you installed a custom theme or some third-party plugin, that’s when everything starts to fall apart.
It happens because other global media library plugins rely heavily on the switch_to_blog() and restore_current_blog() functions, which creates two issues at the same time:
- Not every WordPress function can be hooked with
switch_to_blog(). A good example is theget_post()function that is used quite often. It results in missing media files when supposedly global media files should be displayed. - Since switching between blogs happens too often, it results in performance issues.
The good news is that Multisite Shared Media Library doesn’t have these issues.
I don’t want to dive deep into the technical explanation here; I will only say that the inspiration for creating this plugin came to me when I was working with a new WooCommerce feature at that time – High Performance Order Storage (HPOS). Using the same technique already solved the issue with the excessive use of the switch_to_blog() function. Aside from that, I tapped into the fastest WordPress object cache wherever possible.
Organizing Network Media Files With Folders
Another way of simplifying the whole process of WordPress multisite media management is using media folders.
Simple Media Library Folders is a great solution to work with media library folders specifically within a WordPress Multisite network.
The cool thing about this plugin is:
- When a local media library is in use, folders from this media library will be displayed.
- In cases when either a global media library is in use on a sub-site or even both (with the help of the “Shared media” tab), then the plugin correctly displays the folders from the appropriate sub-site.
The folders are also nicely designed:

Both plugins, Simple Media Library Folders and Multisite Shared Media Library, are fully compatible with each other.
I am also planning to add the “Shared media” folder to the folder list just like this:

But I usually do not add the features to my plugins out of the blue – it keeps the plugins simple, which makes a positive impact on the user experience and performance. So, if you think that this feature will help you in the overall process of multisite media management, please let me know in the comments section below.
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