There are two reasons I like to install WordPress in its own folder, rather than the root. First, I like to keep my root folder uncluttered. I don’t like a bunch of WordPress files that I’ll never be messing with getting in my way. That’s just a matter of personal preference though. The second reason is for security. To prevent automated site scans from easily finding my WordPress files, I simply place them in a separate directory. So… here’s how you do it. It’s actually quite simple.
1. Install WordPress in a subdirectory
Just follow the instructions I gave in my post Installing WordPress Manually. Make sure you create a new directory and upload the WordPress installation files there (that’s step three in the post I just mentioned).
2. Edit the index.php file
Once WordPress is installed, download the index.php from the directory where you uploaded WordPress. You’ll need to open it up and make one small change. Find this piece of code:
/** Loads the WordPress Environment and Template */<br /> require('./wp-blog-header.php');
All you need to do is tell it how to find wp-blog-header.php in its new subdirectory. For example, here’s what the code would look like if I installed WordPress in a directory called example.
/** Loads the WordPress Environment and Template */<br /> require('./example/wp-blog-header.php');
Notice how I added /example just before /wp-blog-header.php. So just add the name of your directory in place of example and that’s all the code editing you have to do.
3. Upload the new index.php file
Now that you’ve made the necessary change to your index.php file, it’s time to upload it to your root directory. Feel free to leave the old index.php file in your WordPress directory, as this will prevent users from looking at the contents of WordPress directory.
4. Tell WordPress what you did
Finally, you need to let WordPress know about the change. First, log into WordPress. The login page will still be at the old URL (for example https://alexmansfield.com/example/wp-login.php not https://alexmansfield.com/wp-login.php). Go to Settings>General and change the Blog Address field (for example, from https://alexmansfield.com/example/ to https://alexmansfield.com/). Save your changes and that should do it!
If you have any questions, please ask them in the comments section below.