Setting the uploads directory

You can use the 'upload_dir' filter

add_filter('upload_dir', 'set_upload_folder', 999);

function set_upload_folder( $upload_data ) { 
  // absolute dir path, must be writable by wordpress 
  $upload_data['basedir'] = trailingslashit(ABSPATH). '/files';
  $upload_data['baseurl'] = 'http://subdomain.wptest.com/files';
  $subdir = $upload_data['subdir'];
  $upload_data['path'] = $upload_data['basedir'] . $subdir;
  $upload_data['url'] = $upload_data['baseurl'] . $subdir;
  return wp_parse_args($upload_data, $upload_data);
}

This code will works no matter if year/month subfolders option is on or off.

Note that, of course, you need to configure your DNS to point the new url to the right folder.

Leave a Comment