Thanks to the open source nature of WordPress, anyone – including hackers – can look up the typical file structure of a WordPress website and know exactly where to start an attack.
Fortunately, rearranging your core WordPress file structure is one method you can employ from your security arsenal to combat hacks and bolster your site's defenses.
So in this post, I'm going to walk you through two ways you can customize your file structure for single and Multisite installs, as well as show you the code you need to bring it all together.
Don't forget: Our expert support heroes are ready and waiting – 24/7, rain or shine – to help you with any issues you may have along the way and for free!
All About That Backup
Since customizing your file structure can break your site in one swift move if you're not careful, creating a backup ensures you can restore your site to its former glory in case things go south.
You can backup just your files only if you're pressed for time, but an unabridged, brimming backup is best. You have been forewarned.
For details on how to backup your site, check out some of our other posts:
- How to Backup Your WordPress Website (and Multisite) Using Snapshot
- Creating a Manual Backup of WordPress When It's Down or Locked
- 4 Top WordPress Multisite Backup Solutions Tested and Reviewed
- 7 Top Premium and Freemium WordPress Backup Plugins Reviewed
In the event that your files can't communicate with your database to display your site, error messages are printed on the front end of your site with some sensitive information. It can be helpful to get rid of this by turning on error logging so any issues are discreetly printed in a log only you can access.
For details on how to disable front end error reporting and enabling your error log, check out our post Debugging WordPress: How to Use WP_DEBUG.
Speaking of front-end errors, reorganizing your file structure takes your site offline for a few minutes while you complete the process so setting up a temporary redirect (302) can help keep your visitors (and Google!) happy while you switch things up. You can check out our post Creating Redirects for WordPress (and the Best Plugins for the Job) for details on 302 redirects and how to set them up.
Changing Your File Directory
The first kind of change you can make is to move all but two files away from the root of your site to a separate directory. Typically, doing this means you would have to change your site's URL from www.your-site.com to something similar to www.your-site.com/core-files/, but it's possible to keep your site's address the way it is while still moving your files into a directory.
Hackers would assume by your URL that all your files are located in the root of your install, but they quickly realize this isn't the case when they aren't able to hack your site. Since they won't be able to easily guess where your files are located, they're more likely to stay untouched.
Creating a New Directory
Start by creating a new directory in the root of your site. You can choose to do this with SSH and the command line, FTP with a program such as FileZilla or through your control panel's file manager.
In cPanel, go to Files > File Manager after logging in and locate your site's files. In the root, click the Folder button at the top of the page and enter a name for your new directory.

The idea here is to name your new folder in a way that isn't obvious. For example, don't name your new directory “wordpress,” “wp-core,” your site's name or something similar. Try to pick a name that wouldn't be easily guessable for hackers, but that's still clear to you.
When you're done, click Create New Folder. You should see it listed among your other files. Before you move any of your files, you need to update your WordPress address which tells your site where your core files are located.
Updating the URL for Your Files
Log in to your WordPress site if it's a single install and go to Settings > General in your admin dashboard. Add a slash to the end of your site's address in the WordPress Address (URL) field, followed by the name of the directory you created. Don't add a trailing slash at the end.

Click Save Changes at the bottom of the page when you're done. Your site should be unavailable now, but don't panic since that's a normal part of the process.
If you have installed a Multisite network, you won't be able to update your WordPress address from your super admin dashboard. You need to hard code it into your wp-config.php file instead.
You could also choose to do this for single installations as well, but keep in mind that you won't be able to update the URL in your dashboard afterward.
Open your wp-config.php file and add the following lines toward the bottom of the page, but before the /* That's all, stop editing! Happy blogging. */
line:
Just be sure to replace application
with the actual name of the folder you created. If your domain doesn't have an SSL certificated installed, you also need to replace the https
portion in both lines to http
.
Save your changes and ignore any error messages or the general unavailability of your site for now. It's time to move your core files.
Moving Your Files
In cPanel, go back to your file manager and the root of your site. select all your files and folders other than the new folder you just created a bit earlier. Once they're all highlighted, drag and drop them into your new directory.
No comments:
Post a Comment