WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I currently use a Wordpress network in order to run a number of sites, which all use the same template, plugins and images. As posts appear on a multiple sites, it makes sense to only upload images to one location (and have one copy of an image), rather than multiple ones.

Could I perhaps achieve this by creating a custom rewrite? Or is there a better way to achieve this?

Background information

I am using WPThree Broadcast to 'broadcast' an image over multiple sites, and therefore also copy the images into their respective image libraries. I don't want the server to get cluttered with ten copies of the same image so instead am checking to see if the image is already in a site's wp_posts table, and then if not copying the post and post_meta data into that site's tables.

However, I do not wish to copy the actual image into a new upload folder, as the default WP is configured to do (e.g. into /wp-content/blogs.dir/2/files/), so instead I want all images to be uploaded to /wp-content/uploads/, the default upload folder for a standard WP installation.

share|improve this question
up vote 4 down vote accepted

You can pretty simple add some actions to archive this.

function wpse_16722_main_uploads() {
add_action('load-media-new.php', 'wpse_16722_main_uploads');
add_action('load-media-upload.php', 'wpse_16722_main_uploads');
add_action('load-media.php', 'wpse_16722_main_uploads');
add_action('load-upload.php', 'wpse_16722_main_uploads');
add_action('admin_init', 'wpse_16722_main_uploads');

This will change the current sub-blog to user your main-site with the help of switch_to_blog and of course you want the main side by the id 1.

You can also add a function to rewrite the upload folder to only /uploads without the subdirs:

function wpse_16722_upload_dir( $args ) {
    $newdir = '/';

    $args['path']    = str_replace( $args['subdir'], '', $args['path'] ); //remove default subdir
    $args['url']     = str_replace( $args['subdir'], '', $args['url'] );      
    $args['subdir']  = $newdir;
    $args['path']   .= $newdir; 
    $args['url']    .= $newdir; 

    return $args;
add_filter( 'upload_dir', 'wpse_16722_upload_dir' );
share|improve this answer
I'm afraid this won't work with WP 3.5 - the new media manager is written in backbone.js so switching doesn't work. – Ollie Dec 24 '12 at 16:31
Yes it does, switch_to_blog has nothing with backbone or jQuery to do. It simply change the upload path and media-library to main-site. – Pontus Abrahamsson Dec 24 '12 at 16:41
Have you really tried this yet? – Pontus Abrahamsson Dec 27 '12 at 8:11
I've ended up using just the second part of your answer to rewrite the upload folder to use /uploads, which doesn't require using switch_to_blog(1) which is where I was previously having issues. Thanks for your help. – Ollie Jan 4 '13 at 9:12

In the post "How to Change the Default Media Upload Location in WordPress 3.5" by Editorial Staff, they show how to change the upload dir in wp-config.php :

define( 'UPLOADS', 'wp-content/'.'files' );
share|improve this answer
Unfortunately, this constant don't work in Multisite, as asked by the OP :/ – brasofilo Jan 30 '13 at 4:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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