Wordpress - 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 );
Came here to find out how to move uploads outside the WordPress root. In the end I kept it as simple as creating a symlink and it works just fine.
$ pwd
/var/www/wordpress
$ cd ..
$ mkdir uploads
$ chmod 755 uploads
$ ln -sf /var/www/uploads /var/www/wordpress/wp-content/uploads
Source: Upload folder of Wordpress outside the project
For an existing project:
$ pwd
/var/www/wordpress
$ mv /var/www/wordpress/wp-content/uploads /var/www/uploads
$ chmod -R 755 /var/www/uploads
$ ln -sf /var/www/uploads /var/www/wordpress/wp-content/uploads