Move WordPress Uploads Out of WordPress Directory

Here’s a simple one (which took me many hours to correctly configure). This little script, inserted into a custom plugin or functions.php in a child-theme will allow you to move your uploads folder out of the WordPress directory. Keeps things neat and tidy for my purposes.

Currently I have wordpress in its own directory, ie.

Now assume publicly facing url is, that makes my uploads – a terribly unprofessional looking URL.

With this code you can move the uploads directory to the top folder. Be sure to move the files, or use Better Search and Replace to change your DB if required.

function ($dirs) {
$new_upload_dir = '/home/domains/';
$new_baseurl = '';
$dirs['path'] = $new_upload_dir . $dirs['subdir'];
$dirs['basedir'] = $new_upload_dir;
$dirs['baseurl'] = $new_baseurl;
$dirs['url'] = $new_baseurl;
return $dirs;
15 // default is usually 10

Note: you’ll need to work out where ‘$new_upload_dir’ with some detective work of your own. Good luck!

Leave a Reply