WordPress has a feature which gives you the ability to relocate and rename the “wp-content” directory that holds the themes, plugins and uploaded files used by your blog. Moving this directory is good from a security perspective too.
Here I will show how you can move the wp-content and plugins directory to a custom location on your web server. Update: From WordPress 3.5+, you can also change the default media upload location (instructions below), aka Uploads directory found inside wp-content.
Move WordPress wp-content directory
To move the wp-content directory, add the below two
define() directives to your WordPress
wp-config.php (configuration) file, replacing with appropriate paths on your server.
/* Move wp-content directory */ define('WP_CONTENT_DIR', 'new/path/to/wp-content'); // no host name, no trailing backslash define('WP_CONTENT_URL', '/url/to/wp-content');
WP_CONTENT_DIR, is used to specify the actual path of the content directory on your server, while the
WP_CONTENT_URL speficies the URL through which the contents inside the directory can be accessed.
If you are not sure about the exact path, here’s another way to define path using
$_SERVER['SERVER_NAME'] global variable:
/* Move wp-content directory */ define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/content'); define('WP_CONTENT_URL', 'http://' . $_SERVER['SERVER_NAME'] . '/content');
$_SERVER['DOCUMENT_ROOT'] will construct a path relative to the document root, while
$_SERVER['SERVER_NAME'] does the same for your web server.
Move WordPress Plugin Directory
If you want to move the WordPress plugins directory to a custom location, you have to define PLUGIN_DIR in your configuration file, similar to how CONTENT_DIR is defined for wp-content:
/* Move plugins directory */ define('WP_PLUGIN_DIR', 'new/path/to/plugins'); define('WP_PLUGIN_URL', '/url/to/plugins');
/* Move plugins directory */ define('WP_PLUGIN_DIR', $_SERVER['DOCUMENT_ROOT'] . '/plugins' ); define('WP_PLUGIN_URL', 'http://' . $_SERVER['SERVER_NAME'] . '/plugins');
Move WordPress Upload directory
To rename or move the upload directory anywhere within the wp-content directory you can use this code:
define( 'UPLOADS', 'wp-content/'.'files' );
Or, if you would like to move it to the root of your server, use this:
define( 'UPLOADS', ''.'uploads' );
Defining path to WordPress plugins folder may also help you resolve problems with those plugins that have a hardcoded path to wp-content.
If at any time you wish to go back to the original structure, simply delete the above added lines from
wp-config.php file and move back the folders to the original locations.