WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi I want all my uploads to be uploaded to a subdomain on my site instead of 'wp-content/uploads'

I created a subdomain cdn.mysite.com and i want all the uploads to go there instead.

I want my uploads to be cdn.mysite.com/uploads/year/month/mediafile

Just as the uploads automatically create a folder for the uploads i want it to do the same when uploading to the subdomain.

How can I accomplish this.


I found this plugin that is suppose to place the image path options back on wordpress but I'm not so sure i should use it, I don't know if it actually works, I don't want to mess anything up


Also I found this tutorial of how to do this from the wp-config.php file but it's only explaining changing the name of the folder not changing the path as in placing a subdomain.


I want to try the second option, editing the wp-config.php file but I don't know how to edit that line of code for subdomains, also I'm afraid that if we do figure out how to add the subdomain option to the wp-config file that when I upgrade wordpress it will disappear and my images may mess up.

What should I do?

share|improve this question

Add the following to your theme's functions.php file, making sure you replace the example CDN URL with your own:

function my_cdn_upload_url() {
    return 'http://mk124.yourcdn.com/yoursite/wp-content/uploads';
add_filter( 'pre_option_upload_url_path', 'my_cdn_upload_url' );
share|improve this answer

Are the sites hosted in such a way that you could create symbolic link within your primary site's directory structure to the physical storage location of cdn.mysite.com? You'd be linking wp-content/uploads -> /path/to/storage/for/cdn.mysite.com/uploads .

You'd likely need both sites' hosting running under the same user, but if they're co-located, this might be as simple as a symlink.

share|improve this answer
yes they are hosted under the same user........ the way it's set up is that the root of mysite.com has a folder called files and the subdirectory cdn.mysite.com will point to that folder or is there another way to set this up – Mihad Aiko Jan 31 '13 at 2:14
i just realized that by creating a subdomain on the site and the subdomain files actually linking to the folder on the site won't make the site go any faster and that was my intentions :( – Mihad Aiko Jan 31 '13 at 2:22
Actually, it will. Most browsers have a limit to the number of connections they can make to a single domain at a given time. By putting some of your content in a subdomain, you increase that limit by at least a factor of 2. – Matt Shelton Jan 31 '13 at 3:14
So, to answer your other question. If your directory layout looks something like this: site site/wp-content site/files site/files/cdn.mysite.com and you have shell access to it, you can create a symbolic link from within site/wp-content. The command would look something like: mkdir -p site/files/cdn.mysite.com/uploads ln -s site/files/cdn.mysite.com/uploads site/wp-content/uploads – Matt Shelton Jan 31 '13 at 3:14
Matt, no need to use symlinks, it is possible to set two WP settings for that. Nowadays, they are in /wp-admin/options.php. – brasofilo Jan 31 '13 at 3:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.