How to move wp-content (or uploads) outside of the WordPress directory

You have to define WP_CONTENT_DIR and WP_CONTENT_URL:

const WP_CONTENT_DIR = '/path/to/new/directory';
const WP_CONTENT_URL = 'http://content.wp';

The new path must be accessible for read and write operation from the WordPress core directory. You might need a helper function to add the new directory path to the open_basedir list:

/**
 * Add a new directory to the 'open_basedir' list.
 *
 * @link   http://www.php.net/manual/en/ini.core.php#ini.open-basedir
 * @param  string $new_dir
 * @return void
 */
function extend_base_dir( $new_dir )
{
    $separator=":"; // all systems, except Win

    // http://stackoverflow.com/a/5879078/299509
    if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) )
        $separator=";";

    $dirs = explode( $separator, ini_get( 'open_basedir' ) );

    $found = array_search( $new_dir, $dirs );

    // Already accessible
    if ( FALSE !== $found )
        return;

    $dirs[] = $new_dir;

    ini_set( 'open_basedir', join( $separator, $dirs ) );
}

Now call it like this:

extend_base_dir( WP_CONTENT_DIR );

Leave a Comment

tech