Using WordPress, it’s a poor assumption to assume the wp-content
, plugins
, and uploads
folders are always in the same place, or even always called by those names.
The configuration you see above is a sample WordPress root directory. This isn’t uncommon. Many people who manage their installs with version control such as Git probably recognize this format.
As you can see above, WordPress core has its own folder, wp
, so that core is not at the root level. This allows us to include WordPress as a submodule of our project, and makes for a cleaner experience.
You’ll also notice that wp-content
is actually called content
.
Now you can see why it’s not a good idea to hard code the uploads
, plugins
, or wp-content
directories into your plugins.
This point was made by Pippin Williamson on Twitter the other day, and he and Brad Touesnard discussed it on Apply Filters yesterday — an excellent podcast by the way.
How to change default directories
You can see how to edit wp-config to define the wp-content
directory and URL using constants in wp-config.php
.
define('WP_CONTENT_DIR', __DIR__ . '/content' );
define('WP_CONTENT_URL', 'http://mysiteurl.dev/content');
You can similarly alter your default plugins directory:
define( 'WP_PLUGIN_DIR', dirname(__FILE__) . '/content/plugins' );
define( 'WP_PLUGIN_URL', 'http://mysiteurl.dev/content/plugins' );
And again for uploads:
define( 'UPLOADS', '/content/uploads' );
You can learn more about various things you can define and utilize with this excellent Codex resource.
How to reference default directories, the right way
Now, let’s show a couple examples for referencing these directories the right way.