Understanding the WordPress File and Directory Structure

Posted on May 21, 2016 by in Tips & Tricks | 26 comments

Understanding the WordPress File and Directory Structure

While it’s entirely possible to interact with your WordPress website only through the dashboard, understanding how your install is structured, and which files perform which functions, is crucial in order to attain a higher degree of control over your site. At the very least, this understanding will enable you to troubleshoot any errors that might arise much more easily.

Each WordPress install starts out with the same directory structure and core files. Every plugin or theme you install, every script you add, and every error screen that appears, is possible thanks to the CMS’s backbone. While the idea of poking around these files may seem intimidating at first, it’s much simpler than it looks.

Over the course of this article, we’ll review the contents of the most important WordPress folders, paying special attention to the core files that power your site.

Introducing the WordPress Directory Structure

The WordPress file structure is honestly pretty simple at the higher levels. You have your public_html folder, where its three key folders are located, as well as a lot of important files such as wp-config.php and .htaccess. Even if it’s your first time poking around in the back of your WordPress installation, chances are that you’ve already familiar with those names.

In order to access these files and folders, you must use either your hosting service’s cPanel file manager, or a File Transfer Protocol (FTP) client. For the purposes of this guide, we’ll be using FileZilla. Regardless of your choice, this is what the inside of your public_html folder should look like:

Screenshot of the public_html folder as seen from an FTP manager.

Before we jump into those three top level folders, let’s take a look at some of the files laying around inside public_html. First of all, we have .htaccess (short for “hypertext access”). This enables you to control permalink structure, files, folders, and access to them across your WordPress installation. A pristine .htaccess file should look as follows:

# 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

Then we’ve got index.php, which will be returned as your homepage by default unless it’s superseded by either a front-page.php or a home.php file:

Screenshot of index.php as seen from an FTP manager.

Another crucial file in this directory is wp-config.php. This handles WordPress’ base configuration, and includes your MySQL settings, secret keys, and database table prefix. This is what your database settings should look like:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'notarealname');
/** MySQL database username */
define('DB_USER', 'notarealuser');
/** MySQL database password */
define('DB_PASSWORD', 'notarealpassword');
/** MySQL hostname */
define('DB_HOST', 'localhost');

Other notable files on this directory include wp-activate.php, wp-signup.php, and wp-signup.php, which together handle the signup, login, and user confirmation process. We’ve also got wp-comments-post.php (which handles the commenting function and prevents comment duplicates), and wp-settings.php, which sets up some common WordPress variables.

Having covered those, let’s move onto the first of the top level folders, wp-admin.

The wp-admin Folder

Screenshot of the wp-admin folder as seen from an FTP manager.

As its name implies, this is the folder that houses the files powering your admin tools as a WordPress user. For example, admin.php (which is at the heart of the folder), enables connection to the database, displays the WordPress dashboard, and performs any other number of key functions, such as checking whether any given user is in fact the admin in question. If they are, the script proceeds to call upon the wp-load.php file, which in turn loads the wp-config.php file:

/**

* In WordPress Administration Screens
*
* @since 2.3.2
*/
if ( ! defined( 'WP_ADMIN' ) ) {
define( 'WP_ADMIN', true );
}

if ( ! defined('WP_NETWORK_ADMIN') )
define('WP_NETWORK_ADMIN', false);
if ( ! defined('WP_USER_ADMIN') )
define('WP_USER_ADMIN', false);
if ( ! WP_NETWORK_ADMIN && ! WP_USER_ADMIN ) {
define('WP_BLOG_ADMIN', true);
}

if ( isset($_GET['import']) && !defined('WP_LOAD_IMPORTERS') )
define('WP_LOAD_IMPORTERS', true);
require_once(dirname(dirname(__FILE__)) . '/wp-load.php');

If you pay attention to the names of the files in this folder, you’ll find that most of them correspond to the functions you’ve come to know on the WordPress dashboard. For example, profile.php powers the user profile administration screen, while theme-install.php controls the theme installation panel, and plugin-install.php does the same for the plugins panel.

As for the other important folders inside of wp-admin, images is filled with images used in the WordPress administration panel, css and js are devoted to CSS code and JavaScript scripts respectively, and network houses the PHP files necessary to power WordPress multisite.

The wp-content Folder

This is the section of the back end where you’re likely to spend most of your time during the course of your relationship with WordPress. Its two most popular functions are located inside – of course, we’re talking about themes and plugins:

A screenshot of the wp-content folder as seen from an FTP manager.

The plugins Folder

A screenshot of the plugins folder as seen from an FTP manager.

Each plugin you upload to WordPress will have its own subfolder within the plugins folder, as seen in the example above. The contents of each of these vary from plugin to plugin. Here, for example, is a quick look inside the Akismet plugin’s folder:

A screenshot of the Akistmet plugin folder as seen from an FTP manager.

As we’ve mentioned in multiple troubleshooting articles such as Getting the 403 Forbidden Error in WordPress, Here’s How to Fix It and How to Fix the 500 Internal Server Error on Your WordPress Website, disabling plugins via FTP can be a necessary step to solve compatibility issues.

The themes Folder

A screenshot of the themes folder as seen from an FTP manager.

As with plugins, each theme you install on your WordPress site gets its own corresponding folder on the back end, which you’ve probably already seen unless you’ve been uploading every theme through the dashboard rather than using FTP.

The first thing you’re likely to see as you access any given theme’s folder is a bunch of PHP files, which together make up its building blocks. Using Divi as an example, in its main folder you’ll find a 404.php, a functions.php, a sidebar.php, and a style.css file, among many others. Divi also includes separate folders for its css, images, and js – which are pretty much standard across most themes. However, a couple of the other folders are quite clearly unique to the theme, such as epanel and et-pagebuilder – whose names you’ll recognize if you’ve had the chance to tinker around with Divi before:

A screenshot of the Divi theme as seen from an FTP manager.

The wp-includes Folder

A screenshot of the wp-includes folder as seen from an FTP file manager.

The final top level folder in the WordPress directory is wp-includes, and it’s a big one. Where wp-admin includes all the files necessary to power said admin functions, and wp-content stores all your themes and plugins, wp-includes is what makes the rest of your site run like clockwork.

This folder is, in fact, so crucial that it’s where most of the WordPress core files are stored. Right off the bat, a fresh WordPress install will include over 140 different files in the main directory, and 14 different folders (at the time of this writing) including certificates, fonts, js, theme-compat, and widgets.

These subfolders, however, aren’t quite as important as the files included in the main folder, such as functions.php. This little file is considered to be part of WordPress’ core, and it’s jam packed with a lot of the little functions that enable your WordPress installation to work. As an example, these lines of code are the first things you’ll see if you open the file on a text editor, and they’re just a regular function meant to transform dates into different formats:

/**
* Convert given date string into a different format.
*
* $format should be either a PHP date format string, e.g. 'U' for a Unix
* timestamp, or 'G' for a Unix timestamp assuming that $date is GMT.
*
* If $translate is true then the given date and format string will
* be passed to date_i18n() for translation.
*
* @since 0.71
*
* @param string $format Format of the date to return.
* @param string $date Date string to convert.
* @param bool $translate Whether the return date should be translated. Default true.
* @return string|int|bool Formatted date string or Unix timestamp. False if $date is empty.
*/

function mysql2date( $format, $date, $translate = true ) {
if ( empty( $date ) )
return false;

if ( 'G' == $format )
return strtotime( $date . ' +0000' );

$i = strtotime( $date );
if ( 'U' == $format )
return $i;

if ( $translate )
return date_i18n( $format, $i );
else
return date( $format, $i );
}

Other key files include cache.php (which handles the processes of adding and removing data from the cache, as well as closing or resetting it), links.php (which includes functions that power WordPress’ links feature), and version.php (which states your version of WordPress).

Conclusion

Although delving into the back end of your WordPress install is understandably scary, with a little practice and a bit of poking around, you’ll soon come to know the ins and outs of its directories and core files by heart. This knowledge will no doubt come in quite handy in the future, whether you need to troubleshoot an error, implement a simple tweak, or simply astound your dinner guests with your encyclopedic knowledge of WordPress trivia (and only one of these applications is not true!).

Every journey begins with a few short steps, however, and in your case those are:

  1. Get acquainted with the WordPress directory structure, especially the wp-admin, wp-content, and wp-includes folders.
  2. Familiarize yourself with the WordPress core files, including wp-config.php, functions.php, and .htaccess.

Have you ever unwittingly broken your WordPress installation by poking around its back end? Don’t worry, we’ve all been there. Subscribe and share your experiences with us in the comments section below!

Article thumbnail image by Rashad Ashurov / shutterstock.com

26 Comments

  1. Thanks Tom,
    Wordpress structure has gone better from what it used to be. The file structure using file manager has also gotten better, because someone can now drag and drop without actually opening individual folder.

    Great post and good job!

    • Tom Ewer

      Thanks for your input, James. 🙂

  2. Hello people,

    Nice post but can you send me a sheet with contains the files that change after updating WordPress and also of (Divi) Theme?
    If i tweak the function file or config (salt and key) are they still existing?
    For the theme file, i know that i can make a childtheme, but i am interesting in what files are changing after update.
    cant find any posts or tuts about it!

    Please help me and thanx!

    Jeroen

    • All files can be concerned by an update. Each release touches one or the other… It depends on what the update is intended for.
      At each update, WordPress releases a change log which explains what the changes are.. ans so does ET with Divi or any theme they have.

      WordPress versions : https://codex.wordpress.org/WordPress_Versions
      Click on “changelog”

      To see the changelog of ET themes or plugins, go to your dashboard/theme.. and guess what… click on “changelog” 🙂

      • All files, except the .htaccess and wp-config.php files. These are untouched, since they are not part of the WP installation package, but created upon installation. Only the wp-config-sample.php can be updated.

        Therefor, never tweak WP core files (other than the two mentioned above) or original plugin or theme files. Always use custom plugins or child themes for that.

  3. Thank you for this much needed information. A newbie and was thinking this is way beyond my brain!!. You have save the day

    • Tom Ewer

      No problem, Ajay!

  4. The whole idea of WP and Divi is to get away from all that and focus on content. Sure I can play with the spark gap on my engine, advance the timing, adjust tire pressure and so forth. But that isn’t why we have cars. It’s to get from point A to point B without a second thought if I should have retard my timing. I stopped building websites because I was so tired of tweaking the code. I just wanted to get it done and move on. Time is money. 😉

    • Tom Ewer

      That’s definitely a big benefit for the average person using WordPress, and undoubtedly why it’s been so successful. If you don’t want to tweak, you don’t have to!

  5. Thank you for that insight

  6. I was just reading about directory structure this week. I am learning wordpress dev. The update can affect everything. Latest wordpress brought some improvements that generate a conflict with Divi theme. I had to rebuild everything cose i didn’t have a child on.

    • Tom Ewer

      Thanks for your insight, Jordan. Glad you’re finally getting your head around the fundamentals!

  7. Excellent post. I have been wondering about the basic structure of WordPress configuration and there I am. Amazingly I have been using WordPress for a while now but never really understood how it works. Thank you Tom

    • Tom Ewer

      Glad we could be of help, Azad!

  8. I’m afraid you lost me in the second paragraph. I don’t know what CMS is, or at least I don’t know what it stands for. If you put in an abbreviation in an article designed to help me understand something better, then please at least tell me what the acronym stands for in parentheses. Thanks….

    • CMS means “Content Management System”. WordPress In itself is a CMS.

    • Content Managing System (CMS)
      Other word commonly used for WordPress (means database powered)

    • Dear David Wikipedia can help you with such queries, however if you know WordPress you should know that WordPress is a CMS, which stands for CONTENT MANAGEMENT SYSTEM, cheers!

    • Tom Ewer

      Hi David,

      Sorry for confusing you. While I normally would include the definition of an acronym within an article, I assumed anyone interested in learning more about WordPress’ file and directory structure would recognize “CMS”.

      Thanks Anthony, James, and Projeter for jumping in and clearing up the confusion!

      Cheers,

      Tom

  9. Thanx Eric for your words,
    for the divi theme i have a childtheme, not really necessary because divi has a custom css feature, and in combination with jetpack you can even preview
    What you made.
    But how can i make sure that things that i tweaked in wordpress for safety in function file, are still there.
    Do i have to make a list with my tweaking changes and put again in the file when it changed or is there some way to make a child-wordpress-function-file with my changes

  10. “Other notable files on this directory include wp-activate.php, wp-signup.php, and wp-signup.php, ”

    Typo, correct?

  11. Good article, although you might want to mention that some things might differ depending on the hosting server. The “public_html” folder for example might be called differently, like “www”. Also, the .htaccess file will only be available on Apache servers, not in servers using Nginx. And even on Apache servers, it often won’t be created until you save the permalink structure in WordPress.

    • Tom Ewer

      Good addition, Ruud. That information was slightly outside the scope of the article, but it’s definitely worth pointing out here, nonetheless.

  12. It really important to have knowledge regarding WordPress file and core directory structure.Many times when you need to use Filezilla these are vital elements.We can only manage when we know each directory structure.
    Thank you Tom for explaining in details.

    • Tom Ewer

      No problem, Payel. 🙂

437,821 Customers Are Already Building Amazing Websites With Divi. Join The Most Empowered WordPress Community On The Web

We offer a 30 Day Money Back Guarantee, so joining is Risk-Free!

Sign Up Today

Pin It on Pinterest