Change WordPress upload path and URL

On a fresh install, I want to move the upload folder to a subdomain (supposed to speed up download). My subdomain links to a folder called static. So I have:

  • Home
    • wp
      • wp-admin
      • wp-content
      • wp-include
    • static

Now I need to tell WordPress where the upload folder is and define its URL. The codex says I should edit wp-config to define UPLOADS relative to ABSPAHT. But if I put define( 'UPLOADS', '../static' ); of course URL in pages are like //mydomain.tld/wp/../static/image.jpg

I’ve looked around, and found many different answers to that (filters, DB edit,…), some of them no longer true (since the media settings page no longer allows to change the upload folder) and some obviously wrong… I want to do it the right way.

I went to the wp-admin/options.php page and set upload_path = ../static and upload_url_path = http://static.mydomain.tld and that seems to work.

But is that how it’s supposed to be done?
And if developpers have removed these options from the media settings page, isn’t there a risk that the feature is later completely removed?

3 s
3

I went to the wp-admin/options.php page and set … But is that how it’s supposed to be done?

Nope. You should never change anything in the WordPress core files because all your changes will be lost during the next update. You should use actions and filters instead:

add_filter( 'pre_option_upload_path', function( $upload_path ) {
    return '/path/to/static';
});

add_filter( 'pre_option_upload_url_path', function( $upload_url_path ) {
    return 'http://static.example.org';
});

Leave a Comment