Giving Wordpress its own directory
Wednesday, October 29th, 2008
Organization is important to me, so something I look for when installing third-party web applications is the ability to keep the application’s files cleanly separated from my own data and any additional files I’m using on the site. Sadly, most applications don’t support this very well but Wordpress is an exception. Wordpress provides the ability to keep your installation in a subdirectory out of the way of the rest of your site while allowing you to display your blog content at the root level. This keeps your web directory cleaner and reduces the risk of important files being modified or deleted accidentally.
This procedure is well documented on the Wordpress Codex but I’m writing it up here as well, as it’s a prerequisite to some other Wordpress techniques I’ll be discussing and would like to keep the instruction all in one place.
A note about terminology
In this, as well as all my tutorials, I use the domain name example.org to refer to your domain. When you see this, substitute your actual domain name. As well, in this article I will assume we’re installing Wordpress into a directory called /wordpress. If you use a different name for your Wordpress folder, just replace “wordpress” in any paths below with whatever name you chose.Portable Wordpress configuration file
This article also strongly recommends using the WP_SITEURL and WP_HOME constants in order to make your Wordpress configuration file more portable, which has the added benefit of making this sort of setup even easier, particularly for those modifying an existing Wordpress site. For background, read my portable Wordpress configuration article but if you’d rather just get to it, add the following two lines to your wp-config.php file, replacing “wordpress” in the first line to whatever directory you want to keep your Wordpress files in.
// ** Hostname settings ** // define('WP_SITEURL', "http://${_SERVER['HTTP_HOST']}/wordpress"); define('WP_HOME', "http://${_SERVER['HTTP_HOST']}");
New Wordpress installations
It’s easy. First, simply unpack Wordpress into a subdirectory of your site. Then all you have to do is copy the index.php file from the WP directory into the root directory of your site, and make a single change. Look for this line:
/** Loads the WordPress Environment and Template */ require('./wp-blog-header.php');
And change it to this, replacing “wordpress” in the path to whatever directory you installed WP into.
/** Loads the WordPress Environment and Template */ require('./wordpress/wp-blog-header.php');
And that’s it! Your blog content will now appear at the root of your site, and your admin area is now at http://www.example.org/wordpress/wp-admin/.
Moving your existing Wordpress installation
Rearranging an existing Wordpress site is a bit trickier than doing this with a clean installation, but don’t let this deter you. It’s still pretty straight-forward. As above, the first thing you should do is modify your wp-config.php file with the code shown above. This will save you the step of changing the URL settings in the WP administration section.
Once you’ve done this, create the folder you would like to store Wordpress in, making sure the name you choose is the same one you specified in the WP_SITEURL line in your config file. Then move (not copy) all your Wordpress files into this new folder. On a typical Wordpress 2.6 installation, these files include:
- Three folders:
wp-admin,wp-content, andwp-includes - Any files beginning with “wp-” and ending with “.php” (eg,
wp-app.php,wp-atom.php, etc) index.phpxmlrpc.php
The license.txt and readme.html files can be moved, deleted, or ignored, as you wish.
Once these files have been moved, copy (not move) that index.php back into the root directory and open it up in a text editor. Look for this line:
/** Loads the WordPress Environment and Template */ require('./wp-blog-header.php');
And change it to this, replacing “wordpress” in the path to whatever folder you just moved your Wordpress files into.
/** Loads the WordPress Environment and Template */ require('./wordpress/wp-blog-header.php');
No changes to your .htaccess file are necessary. Your admin area is now at http://www.example.org/wordpress/wp-admin/ but you should now see your blog appearing at the root of your site, just the way it always has.
Now that Wordpress is cleanly tucked away into it’s own folder, your web site directory is cleaner and more organized, you will now have an easier time updating Wordpress, and the way is paved for doing easier maintenance using some new features of WP 2.6.

