johngirvin.com

John Girvin

This is the blog of John Girvin, a software engineer and web developer based in Belfast, Northern Ireland. He draws on over 14 years of hard won, real world experience of different projects, clients and working environments. Visit the rest of the site to find out more and get in touch.

John is currently working with the Art Technology Group (ATG), developing J2EE based, market leading e-commerce technology.

moving the wordpress wp-content folder

February 26th, 2009 by John Girvin

One of the features added for Wordpress 2.6 and above is the ability to relocate and rename the “wp-content” folder that holds the themes, plugins and (by default) uploaded files used by your blog.

The rationale behind the addition of this feature was to separate the user generated or otherwise customised content of a blog from the core Wordpress system that drives it. This separation greatly simplifies a couple of common Wordpress administration headaches,namely updating Wordpress to a new version for those of us who don’t or can’t use the built in update feature and driving multiple blogs from one copy of the Wordpress system files.

Moving the wp-content directory is actually quite straightforward and is achieved by adding two define() directives to your Wordpress configuration file, “wp-config.php”.

/** set location of content dir */
define('WP_CONTENT_DIR', '/path/to/wp-content');
define('WP_CONTENT_URL', '/url/to/wp-content');

The first of these, WP_CONTENT_DIR, is used to specify the actual filesystem path of the content directory, which need not even be named “wp-content”. Note that, whatever path is used, it must be accessible by the web server process as CSS, images and other files required by client browsers will be served from there. You may wish to consider using the $_SERVER['DOCUMENT_ROOT'] global variable to construct a path relative to the document root, as shown :

define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/wp-content');

The WP_CONTENT_URL definition specifies the base URL from which resources in the content directory may be accessed. This is required as, in many installations, the filesystem and URL namespaces have no direct correlation and are instead mapped in the web server configuration. Taking the example above, where we moved wp-content into the top level of the server document root, WP_CONTENT_URL would be defined as follows:

define('WP_CONTENT_URL', '/wp-content');

If you wish to use the new wp-content folder to store media files you upload for use in your blog posts, you will also need to enter your new wp-content path into the Settings / Miscellaneous Settings / Uploading Files configuration page within the Wordpress administration screens. The screenshot below is taken from Wordpress 2.7.1, other versions of the software may be different.

Wordpress uploaded files path configuration

Wordpress uploaded files path configuration

Unfortunately, these relatively simple changes are not the end of the story. Many popular Wordpress plugins and themes do not (yet?) take account of the fact that wp-content might not now be where it always has been before, and so they fail to work if the directory is relocated. However, we can restore some level of compatibility by using the Apache mod_rewrite functionality to rewrite requests referencing the old wp-content location to reference the new location instead.

The example below shows how to use mod_rewrite to alter requests to /wordpress/wp-content to reference /wordpress-content. To illustrate, a request to load /wordpress/wp-content/themes/mytheme/style.css would be altered to load /wordpress-content/themes/mytheme/style.css. Add the lines shown to the start of the .htaccess file in your Wordpress installation, before the # BEGIN WordPress line, and restart or reload Apache to pick up the changes.

# rewrite wp-content requests to new location
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_URI} ^/wordpress/wp-content(/*)
RewriteRule ^wp-content/(.*)$ /wordpress-content/$1 [L]
 
# BEGIN WordPress
...
# END WordPress

Note that this is only a workaround and isn’t guaranteed to work for all plugins and themes. In particular, this fix cannot help if a plugin or theme uses hardcoded wp-content paths to load PHP code files. In that instance the only thing to do is contact the author of the offending code and pester them for an update!

Moving wp-content isn’t for everyone and I imagine that for a lot of users it won’t be necessary or even helpful. It’s still a new feature (though arguably one that should have been there from the beginning) and for those, like me, that implement it there may be some pain to be endured before common themes and plugins are updated to take account of it. But given how it simplifies the administration of my Wordpress installations, I find it’s worth the trouble.

Have you tried moving your Wordpress content folder? Did you run into any trouble? Share your experience in the comments section below.

John Girvin
Bookmark and Share

John Girvin is an experienced a software engineer and web developer based in Belfast, Northern Ireland. He draws on over 14 years of hard won, real world experience of different projects, clients and working environments.

John is currently working with the Art Technology Group (ATG), developing J2EE based, market leading e-commerce technology.

If you liked this article, why not subscribe to the RSS feed for more?

12 comments on “moving the wordpress wp-content folder”

March 8 2009, 9:37 pm

I installed a WP on the root level of a server. Now the client wants me to make a splash page at SITENAME.com, which would be an HTML page INDEX.html, of course. If I move all the files via ftp into a directory like /blog I know it will confuse the config file or something. What code do I need to put where to account for this move? Really appreciate any time you can give me, I’m stuck on this job on a Sunday and want to finish! Thanks.

March 9 2009, 10:32 am

Since 2.1, you can make a splash page within Wordpress then set it as your first page in the Administration > Settings > Reading settings page as described here:
http://codex.wordpress.org/Settings_Reading_SubPanel

If your front page can’t be made within Wordpress itself, follow the instructions given on this page instead to create a static front page that can be whatever you need:
http://codex.wordpress.org/Creating_a_Static_Front_Page

Hope that helps!

March 12 2009, 6:04 pm

I was wondering how to do this kind of things. Thanks for this post .

I think it could be good for security to split the wp-content from the wordpress files.
With this kind of technique nobody can know where the wordpress folder is. That’s the point.
You don’t think so ?

March 13 2009, 10:35 am

There might be some security benefits, yes. I don’t know of any specifics, but you could easily imagine an attack that put malicious files into the wp-content folder and that it would be made more difficult if the folder was not in it’s usual location, either absolutely or relative to the other Wordpress files.

March 13 2009, 6:27 pm

[...] Moving The Wordpress WP-Content Folder [...]

Kian
August 5 2009, 11:58 pm

If I were to move the content folder to be the same across multiple blogs would they share their content? I would love to make it so that a few blogs could have integrated content and searches. Also has there been an update with the plugin/theme issue that doesn’t involve the workaround you suggest?
Thanks!

August 6 2009, 9:03 am

The blogs could share the files, but they would not share the media database entries so cross-blog search wouldn’t work. I’m not completely sure what you’re trying to achieve, but perhaps Wordpress MU would be able to do what you need.

The plugin / theme issue is down to problems in the plugins and themes themselves and can only be resolved with updates to the individual packages. Most will work, so on your development system just check the ones you’re considering using. It will be obvious if they’re not compatible.

Dan
October 17 2009, 4:32 pm

I added the two lines in my wp-config and now I see nothing. Any idea why?

define(‘WP_CONTENT_DIR’, $_SERVER['DOCUMENT_ROOT'] . ‘/resources’);
define(‘WP_CONTENT_URL’, ‘/resources’);

October 18 2009, 9:57 pm

That’s what I have in my wp-config too. Check the following:

  • What do your WP_CONTENT_DIR and WP_CONTENT_URL resolve to?
  • Is mod_rewrite loaded and working?
  • Did you make the .htaccess file changes?
Dan
October 20 2009, 8:51 pm

I’m a n00b, got it. This all has to appear before the include of settings.php

November 13 2009, 4:06 am

Great! I moved the entire directory structure of my site and the wp-content folder was created under the old / directory. It was all the fault of the Uploading Files configuration routine.

Thanks for the how-to.

January 1 2010, 6:35 am

Thanks a lot, I needed a way to get wo-content absolute path and WP_CONTENT_DIR just did the trick!

share your thoughts?

design & content © 2008-2010 john girvin, all rights reserved.