I have a wordpress multisite, where I would like all the images uploaded through the main site (mysite.com) to be accessible to sub1.mysite.com
and sub2.mysite.com
. All the images should be in one folder without subdirectory (e.g: wp-content/uploads/image.jpg
).
I tried the bellow function, but my images for subdomains are uploaded to wp-content/uploads/sites/#blog_id/
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' );
wp_upload_dir
appends the site-specific sub-directory directly on thepath
argument.subdir
will be empty (or theyear/month
), sostr_replace
'ing it will have no effect. Do you want all uploads in the root folder, or just for the main site?