Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
WordPress Development Quick Start Guide

You're reading from   WordPress Development Quick Start Guide Build beautiful and dynamic websites for your domain from scratch

Arrow left icon
Product type Paperback
Published in Oct 2018
Publisher Packt
ISBN-13 9781789342871
Length 300 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Author (1):
Arrow left icon
Rakhitha Nimesh Ratnayake Rakhitha Nimesh Ratnayake
Author Profile Icon Rakhitha Nimesh Ratnayake
Rakhitha Nimesh Ratnayake
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Introduction to WordPress Development FREE CHAPTER 2. Managing Database Structure, Storage, and Retrieval 3. Designing Flexible Frontends with Theme Development 4. Building Custom Modules with Plugin Development 5. Extending Plugins with Addons, Filters, and Actions 6. Practical Usage of WordPress APIs 7. Managing Custom Post Types and Processing Forms 8. Discovering Key Modules in Development 9. Enhancing Security, Performance, and Maintenance 10. Other Books You May Enjoy

Understanding the role of the WordPress file and directory structure

Beginning WordPress development is not a complex task. It's about making minor theme changes, installing and customizing existing plugins, and using the available hooks. As you move on, complex requirements come your way with the expectation of future-proof solutions. Trying to build such solutions without considering future WordPress, plugin, and theme versions can lead to a nightmare. Getting used to existing WordPress files/directories and knowing their role is vital in developing maintainable solutions. In this section, we are going to look at the existing files and directories of a default WordPress installation.

The following is a screenshot of typical files and directories inside your WordPress installation:

Let's look at some of the most important files and directories inside WordPress:

  • wp-admin: This is where WordPress stores files related to admin-side functionality. The files in this directory are based around the admin.php file. Primary functionalities of these files include checking admin permission, connecting to the database, and loading the admin dashboard features. This directory is upgraded with WordPress version updates and hence the content of these files is replaced.
  • wp-content: This is where WordPress stores user-uploaded files such as plugins, themes, and media files. We can add additional files/directories here without being affected by WordPress version updates. So, the content in this directory will not be replaced.
  • wp-includes: This is the largest directory in WordPress with over 800 files to power the features of the admin dashboard as well as frontend functionality. The primary file in this directory is functions.php, considered as the main WordPress API. This directory is upgraded with WordPress version updates and hence the content of these files is  replaced.
  • .htaccess: This file is where you describe configuration rules for your Apache server. By default, it will contain minimal rules. You can manually add configuration rules based on your requirements. There are plugins that automatically add the necessary configuration rules to this file. This file is used for the configuration of WordPress permalinks. Changing the permalink structure from the WordPress settings section is the simplest way to track rule changes in this file.
  • index.php: This file is responsible for initializing WordPress based on user requests, and serving the response.
  • wp-config.php: This file is used for all the configurations for your site including databases, secret keys, plugins, and theme directory paths. So, it's very important to keep this file as secure as possible. This file is not replaced on WordPress version upgrades and hence you can use your own configurations.

Here, we looked at the most important files and directories involved in development. You can also check the comments of other core files to understand their functionality.

How to choose files and directories for development

The process of WordPress development is slightly more challenging compared to other PHP frameworks. With any other framework, we choose a specific framework version and develop the features for that specific version. It's entirely optional to upgrade our solution's future versions of the framework. However, it's the opposite with WordPress. We can't stick with a specific WordPress version for a long time, especially due to security concerns. Most of you will want to upgrade the version as soon as WordPress releases a new version. Therefore, it's important to develop solutions that don't break with version upgrades. Basically, we should be able to upgrade WordPress without touching any of our code.

So, the first thing you need to understand is where you can place your code files and how you can use the core WordPress files/directories in development. We discussed the main files and directories inside the WordPress directory in the previous section. Let's narrow it down to the files and folders used for custom development. Basically, we have to choose files and folders that are not replaced by WordPress updates. Among the files and folders we discussed, wp-content, wp-config.php, and htaccess are not affected by upgrades. So, our development should focus on these files and folders.

As we mentioned, wp-content is the directory where all the user-uploaded files are stored. So, we need to add our code files inside this directory. Let's explore the contents of this directory to understand where and what kinds of files can be created.

The following is a screenshot of files and folders inside your wp-content folder:

The preceding screenshot contains both default directories and custom directories created based on custom requirements. Let's have a brief overview of the role of each folder:

  • plugins: This is where WordPress stores all the plugins required to run your site. You will get Akismet Anti-Spam and Hello Dolly plugins on initial installation. Afterwards, you can use this directory to add your own plugins as well as install existing plugins from other developers. This directory can be considered as the heart of WordPress development.
  • themes: This is where WordPress stores all your themes that power the design and initial functionality of your site. Initial installation contains a few default themes such as Twenty Seventeen, Twenty Sixteen, and so on. Afterwards, you can use this directory to add your own themes as well as install existing themes from other developers. Unlike plugins, you can only use one theme from this directory at any given time.
  • uploads: This is where all the user-uploaded files for posts, pages, and plugins will be stored. This directory is not created until you upload the first file. Usually, all the media files for posts and pages will be stored with a sub-directory structure of year/month format. You can create unlimited sub-directories to handle files for plugins and themes.
  • languages: This directory is not available on initial installation and is created when you change the language in WordPress. So, it's not important for the development tasks.
  • mu-plugins: This directory stores must-use plugins for your site and is not available on initial installation. A must-use plugin is a plugin that's mandatory to run the site and hence it's not possible to deactivate. These plugins are automatically enabled on all sites of your WordPress installation. Even though these plugins are useful in some scenarios, it's not ideal to use them due to some of the limitations in executing certain hooks. So, we are not considering them for the development tasks of this book.
  • upgrade: This directory is not available by default and is used for storing temporary files for WordPress version upgrades. So, it's important for our development tasks.
  • cache and logs: These are some of the custom directories created by plugins or themes to handle certain features. I have used them in this screenshot to explain the use of custom folders. You can create such custom folders to handle files related to themes or plugins.

After having a quick overview of files and directories, we can come to the conclusion that our primary focus should be on the plugins, themes, and uploads directories inside the wp-content directory. Using code and media files in these directories ensures our solutions are not wiped out by version upgrades.

You have been reading a chapter from
WordPress Development Quick Start Guide
Published in: Oct 2018
Publisher: Packt
ISBN-13: 9781789342871
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime