In WordPress multisite, media uploaded from the subsite users are stored to different subdirectories using blog id into uploads folder. But, if you need to save all media files in one folder rather than uploads folder with lots of child folders, then you are in right place.

Use the following code into your theme functions.php file if you think your theme won’t be changed. Otherwise, mu-plugins is the best option.

0) {
$upload[‘path’] = ABSPATH . ‘wp-content/images’;
$upload[‘url’] = site_url() . ‘/’ . ‘wp-content/images’;
$upload[‘subdir’] = “”;
$upload[‘basedir’] = $upload[‘path’];
$upload[‘baseurl’] = $upload[‘url’];
return $upload;

function make_filename_hash($filename) {
global $user_ID;
return $user_ID . time() . $filename; /*Using time() function for uniqueness*/
add_filter(‘sanitize_file_name’, ‘make_filename_hash’, 10);

You may also read:  Defer parsing of javascript to improve performance in wordpress


Leave a Reply