Understanding the WordPress File and Directory Structure
WordPress is a very user-friendly platform that allows all-comers with little to no coding knowledge to create and manage their websites. While you might not need to know to code, you still need to invest some effort and dedication to manage a WordPress site. A part of that is getting to understand the WordPress file and folder structure. Having this knowledge makes some of the common tasks much easier and less stressful. Furthermore, it is a stepping stone for users who want to customize their websites further or learn more about WordPress development. We created this article to help you understand the WordPress file structure and its importance, as well as to clarify the makeup of the following directories:
Benefits of knowing more about the WordPress file and directory structure
Even though most aspects of running a website don’t require you to have an in-depth knowledge of the WordPress file structure, understanding it could help you troubleshoot some problems. After reading this article, you will know which are the core WordPress files and folders and where they are located. This knowledge will be helpful if you ever need to manually update WordPress via FTP or work on your server control panel.
This article will also cover where the website configuration files are stored. This will help you perform various tasks—debugging errors, adding redirections, blocking some IPs, solving database issues, etc. It will also help you understand where and how your uploaded media files are stored.
Additionally, you will come to know where your themes and plugins are stored, as well as the purpose of some of the additional folders within the wp-content directory. Most importantly, you will get to know how to disable a plugin or a theme via FTP. Knowing this is quite helpful in troubleshooting many common WordPress errors, especially the ones that leave you locked out from your dashboard or prove fatal to your website.
Finally, by getting a thorough grasp on the WordPress file structure, you will be able to judge when to make a backup of your WordPress files (or a single specific file only) and when to make a backup of your whole WordPress website.
Understanding the WordPress file and directory structure
Now that you’ve seen some of the ways knowing the WordPress file and folder structure can benefit you, we can proceed to explore it from top to bottom. To view the WordPress file and directory structure of your website you will need to connect to your server using FTP first. This can be accomplished in one of three ways—by using an FTP client, through the File Manager option within cPanel, or via a file manager plugin within your admin dashboard. Once you’ve connected to your server, position yourself within the root WordPress directory (often called public_html) from which we start our explanation.
Within the public_html file, you will find various folders and files, but we will focus on the most standard configuration as shown below.
Depending on the website, additional folders and files might be present within your root WordPress directory. For example, you might have a .well-known folder, which is used for demonstrating ownership over a domain when adding an SSL certificate. Also, if you have decided to create a subdirectory, its folder would be located in the root WordPress directory. Among other possible additional files, you could see the php.ini file, used for configuring your PHP settings, or robots.txt, used for giving directives to web crawlers on which parts of your website should or should not be crawled.
Going back to the standard WordPress structure, you will notice three folders—wp-admin, wp-content, and wp-includes, all of which we will discuss in this article. As for the files, we will cover the three most important ones—wp-config.php, .htaccess, and the index.php file.
-
The wp-config.php file is an important core WordPress file. It contains information for communicating with your database such as your MySQL settings, SALT keys, and database prefix. By editing the wp-config.php file, you can achieve additional advanced WordPress functionalities like debugging errors. Interestingly enough, the wp-config.php file isn’t included in the WordPress package by default. It is created during the WordPress installation process, using the wp-config-sample.php file as a blueprint.
-
The .htaccess file, standing for “hypertext access”, is an Apache server configuration file that operates on a directory level. So, if you create subdirectories, each could have a separate .htaccess file that operates independently from the .htaccess file found in the root WordPress directory. Among other things, the .htaccess file is used to enable URL redirection, restrict access to certain IPs, or enable password protection.
As this is, by default, a hidden file, you will need to enable the options for showing hidden files to see it. This file is also not a part of a default WordPress package, but it is often created automatically later and placed within the root WordPress directory. If it isn’t, you can simply create it manually and upload it via FTP. We have included the code that is present in a default .htaccess file below, in case you need it.
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
-
The index.php file helps load and initialize your WordPress files when a user requests them. You need to have an index.php file in your root WordPress directory for your website to show properly in the browser. If you don’t have an index.php file, instead of your website, you will see the file and folder structure of your root WordPress directory in your browser window. Furthermore, you would be able to view and/or download files directly from the server via the browser. However, so could anyone else, which poses a security risk. As such, having an index.php in the root WordPress directory is a must.
Similarly, you can often find index.php files in subfolders, serving the same purpose. These files are empty, as opposed to the index.php file in the root WordPress directory. More precisely, they often come with an opening PHP tag and a single comment only – none of which will be shown when the file is executed.
Example:
<?php // Silence is golden.
As such, if a user tries to access the subfolder directly in the browser, he will only see a blank screen, as the index.php within will be executed.
With that being said, of the files within a standard configuration, you should only consider editing the wp-config.php and the .htaccess file, as all remaining files are core WordPress files. Furthermore, we suggest making a backup of your WordPress files before making any changes to the wp-config.php or .htaccess file. Otherwise, you might not be able to access your website after making an error within those files.
Having clarified the general structure within the public_html directory and covered the three most important files within, let us examine the three folders that we mentioned, one at a time.
The wp-admin folder contains all the files and folders required for the WordPress dashboard to properly function. It is one of the two core WordPress folders, alongside the wp-includes folder. Currently, there are seven subfolders within the wp-admin folder: css, images, includes, js, maint, network, and user, as well as many files.
The files and folders are based around the most important file within this folder—admin.php. This file performs many functionalities: displays the WordPress dashboard and plugin admin pages, determines if a user is an admin or not, schedules transient and trash cleanup, loads many other core files from within the wp-admin folder as well as within the root WordPress directory, and so on. One of the core files that admin.php loads is the wp-load.php file, which then loads the wp-config.php file.
Additionally, if you take a look at some file names within the wp-admin folder, you will notice from their names that they serve to enable common administration tasks. For example, install.php enables WordPress installation, while theme-install.php and plugin-install.php provide the administration panels for theme and plugin installation, respectively. Furthermore, widgets.php provides the Widgets panel, while the nav-menus.php provides the Menus panel, both of which are located in the Appearance section.
If you’ve ever tinkered with your WordPress installation, chances are that you are very familiar with the contents of this folder. You can find various folders within, but there are two that will always be present—the plugins and themes folders. Besides them, you will see an index.php file, the importance of which we discussed previously.
We will explain more about these two subfolders below. Apart from that, we will briefly cover some of the other folders you can encounter.
-
Plugins
Every plugin that you install on your WordPress website will get an appropriately named subfolder within the plugins folder. The content of those subfolders varies from plugin to plugin. Simpler plugins might have only a couple of files, while more complicated ones could have an extensive hierarchical structure of files and folders within them.
What is important to know is that by renaming the plugins folder via FTP, you will disable all the plugins you have installed. Similarly, renaming a single plugin subfolder via FTP will disable that plugin. This trick may come in handy when you are troubleshooting a WordPress error that has left you locked out of your admin dashboard. When renaming folders, we suggest you add a suffix to the original folder name (e.g. plugins-disabled or akismet.old) so that you can easily keep track of the folders you changed.
-
Themes
Similar to the plugins folder, every theme you install will get an appropriately named subfolder within the themes folder.
The content of a theme folder can differ a lot based on its authors, but some files and folders are present in any theme. Those include functions.php and style.css, as well as index.php, header.php, footer.php, and other template files. Additionally, themes will have separate folders for css, js, images, and fonts. Most often, they will all be stored within a subfolder called assets, contained within the folder of your theme.
If you plan to make extensive modifications to your website, you should make a child theme and place your custom code inside the functions.php file of the child theme. If you do this with the functions.php file of the main (parent) theme, then the code you add will get overwritten when the theme gets updated. Another possible way to safely modify your site is to create a site-specific plugin and add the code within it.
Apart from that, the advice about renaming folders that we mentioned when talking about the plugins holds here as well. If you rename the folder of your currently active theme via FTP, you will deactivate it. In its place, a default WordPress theme will be activated, provided you have one present on your server. If you haven’t installed a default WordPress theme, you would need to do so first, before deactivating your theme via FTP.
Before we move on to exploring the content of the wp-includes folder, we will cover the additional subfolders that could be within the wp-content folder. Depending on your website, the wp-content folder could contain a lot more subfolders besides the default plugins and themes that we discussed previously. Those include uploads, upgrade, languages, mu-plugins, cache, and many more. The upgrade folder temporarily stores WordPress files every time you update WordPress on your website and is created during the first WordPress update on your website. The uploads folder is created when you first upload a media file to your Media Library and it contains all the media files. Those files are usually stored in a subfolder structure that is labeled by year and month. What is more, after changing the website language in Settings > General > Site Language for the first time, the languages folder is created. The languages folder will then contain the language files necessary for translating your website into a language other than English.
Similarly, the folders of individual plugins and themes could include a subfolder named languages. Within it, you’d get corresponding .pot files used in the process of translating plugin-related or theme-related labels.
Depending on the WordPress website, within the wp-content folder, you could also find a mu-plugins folder that stores must-use plugins for your website. Needless to say, these plugins are automatically activated and can’t be deactivated. The only way they can be disabled is if you remove them from the mu-plugins folder via FTP.
Some caching folders can also create a cache subfolder within the wp-content folder and use it to store cached files. It is worth noting that other plugins you have installed might also create additional subfolders within the wp-content folder to store their data. As such, you shouldn’t be surprised if you see additional subfolders we failed to mention. Having said that, we can proceed to explain the content of the wp-includes folder.
The wp-includes folder is the second core WordPress folder. While the wp-admin folder contains the files and folders related to the WordPress dashboard panel, wp-content contains your plugins and themes, the wp-includes folder contains all the remaining files and folders required for your website to function properly. Therefore, it is important to mention that you shouldn’t edit any of the core WordPress files, especially the ones in the wp-includes folder.
The wp-includes folder is very big, as it currently contains 22 subfolders and 1180 files in total.
The most important file within this folder is the functions.php file, which is considered the main WordPress API. It contains a great number of support functions that enable WordPress to work. Some of the other files you might find interesting are:
version.php – sets the WordPress version you currently use,
wp-db.php – contains functions for connecting to the MySQL database,
widgets.php – core Widgets API, and
sitemaps.php – added in WordPress 5.5 update, provides a list of functions you can use to interact with the XML Sitemaps API.
This concludes our overview of the WordPress file structure. In case you want to delve even deeper into the files and folders and how they are structured, we suggest reviewing the Codex and Developer Resources for more information.
Final Thoughts
Even though understanding WordPress file structure might seem daunting to some and tedious to others, it can often come in handy when troubleshooting errors or customizing your website. In this article, we have given a general overview of the files and folders within a WordPress installation, with special attention given to the more important files or folders. Therefore, we hope this article will prove insightful to a wide range of WordPress users and help to brush up on existing WordPress knowledge for those already familiar with the topic.