I want to change the upload directory for Wordpress from project.dev/wp-content/uploads to cdn.project.dev

Where subdomain cdn has DocumentRoot: HostPath/project.dev/cdn while Wordpress is located at HostPath/project.dev/public_html

Any help is much appreciated.

  • 1
    You can ask how to change the URLs WordPress generates, and the folder that WordPress stores uploads, however the server component will require nginx or apache knowledge which is off topic on this site
    – Tom J Nowell
    Feb 19, 2016 at 16:45
  • 1
    I would also note that this sounds like a micro-optimisation, you would get more out of using a free CDN such as Photon or another alternative
    – Tom J Nowell
    Feb 19, 2016 at 16:46

2 Answers 2


If all you want to do is to have a "cdn" type url, the easiest solution that do not require any programing is to make HostPath/project.dev/cdn a symlink to project.dev/wp-content/uploads. This way for theOS both paths are essentially the same. This should be easy to do if you are in full control of the server and/or have SSH access, or might require help from your hosting if you do not have this kind on access.

Another option if you have control on the web server configuration is to map the "document root" of the cdn.project.dev to the dev/wp-content/uploads directory.

Putting the uploaded files outside of the wordpress directory tree,as the question literally asks, is not a great idea as it is likely to break all kinds of external tools like backup utilities.


You can create a very simple plug-in to meet your needs. Here is one based on the now-defunct directory-control plugin, previously available at https://github.com/johnbillion/directory-control.

  1. In your plugins directory, create a directory called custom_upload_dir
  2. In that directory, create the following file called custom_upload_dir.php

    Plugin Name:  Custom Upload Directory
    Author URI:   https://wordpress.stackexchange.com/a/253797/111682
    function custom_upload_dir_impl( $uploads ) {
        if ( defined( 'WP_UPLOAD_DIR' ) ) {
            $uploads['path'] = str_replace( WP_CONTENT_DIR . '/uploads', WP_UPLOAD_DIR, $uploads['path'] );
            $uploads['basedir'] = str_replace( WP_CONTENT_DIR . '/uploads', WP_UPLOAD_DIR, $uploads['basedir'] );
        return $uploads;
    add_filter( 'upload_dir',     'custom_upload_dir_impl', 1 );
  1. In your wp-config.php file define the WP_UPLOAD_DIR constant used by the plugin.
  2. In Wordpress Admin, enable the plug-in
  • link only answers are not much of an answer, and in any case there is an additional server configuration component required here Aug 12, 2017 at 8:33
  • "Not much of an answer" solves the OPs issue and is the only answer that's been posted for 7 months.
    – Mike Godin
    Aug 13, 2017 at 1:46
  • eternal link expire.plugin stop being maintained etc, which is why they are not a good answers. Aug 13, 2017 at 3:22
  • ... and as predicted it is no longer available :( Jan 27, 2018 at 7:47
  • @MarkKaplun you were prescient.
    – Mike Godin
    Jan 29, 2018 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.