We use cookies to understand how you interact with our site, to personalize and streamline your experience, and to tailor advertising. By continuing to use our site, you accept our use of cookies and accept our Privacy Policy.
Contact Us
Contact Us
Sign in
Sign in
April 15, 2019

As a WordPress hosting client, it’s not essential that you know the nitty gritty details of how WordPress runs behind the scenes. In fact, WordPress was created so that people could focus on writing and publishing, not on the technical details. But it’s useful to have a basic understanding of the platform to help you diagnose problems more easily and understand why WordPress behaves as it does.

So, let’s dive in and discover the basics of what WordPress is and how it works.

WordPress explained: an introduction to the platform

New site owners may be wonder, what is WordPress, and how does it work? WordPress began as a simple blogging platform in 2003. Over the years, WordPress evolved into a full-blown website builder and content management system (CMS) created so that people could focus on their content without getting lost in the development of their website.

Today, WordPress is by far the most popular CMS used by site owners. According to Web Tech Surveys, over 39% of all websites run on WordPress. The following sections will explore what WordPress does and why it’s so popular. 

The Building Blocks of a WordPress Site

Carl Sagan once said, “If you want to make an apple pie from scratch, you must first create the universe.” Something similar is true of a complex piece of software like WordPress. In order to fully understand the question, “how does WordPress work?”, you’d have to be a developer, a network engineer, a database administrator, and a designer. It would take (several) books to explain the WordPress universe from scratch, so let’s stick with the basic building blocks.

WordPress is an open source application that relies on three key components: a web server, a database, and a PHP programming language interpreter.

  • Apache. Apache is a web server. It is responsible for listening to requests from a browser and sending a response – the web page – back. When Apache receives a request, it gives the URL and other information to WordPress. WordPress then generates the corresponding web page.

  • MySQL. MySQL is a relational database – it stores information in tables. The files that make up your website live in the tables of this database. For example, all the blog posts on a WordPress site are stored in a table called wp_posts.

  • PHP interpreter. WordPress core is a collection of files that contains code written in the PHP programming language. The execution of these files generates your web pages.

The PHP files can be divided into two basic groups:

  • Template files – the skeleton of your website, which dictates how it looks 
  • Function files– reusable chunks of code and constants that are used within templates and elsewhere in WordPress’ code. These files have more to do with functionality than appearance.

Since WordPress is a content management system, some site owners may be more interested in the template files because they help generate the web pages.

Generating an HTML page

Now that we’ve covered the basic components of WordPress, let’s revisit our original question, how does WordPress work? Naturally, it starts with a configuration file.

Setting up the wp-config.php file

When the Apache web server receives a request for a page, WordPress first runs several set-up scripts, including the wp-config.php file that provides information such as which database WordPress should use. Once wp-config.php is loaded, WordPress will set default constants based off this information. For instance, the default constant for maximum file sizes will be set at this point.

Executing Template Files

After the set-up phase is complete, WordPress starts the process of generating an HTML page by executing a template file. The template files are a mixture of HTML code and PHP code. The role of the PHP code is to fetch data from the MySQL database and then process it into HTML. 

Exactly which HTML is output depends on various factors: the available data, which user is logged in, the time of day, and more. Other functions are executed on template pages, but the ultimate goal is to dynamically generate an HTML page that can be sent to the requesting browser.

A complex set of rules dictates which of the many templates gets executed, but it’s primarily determined by the URL of the request. For example, if the URL is the site’s home page and the site is configured to display a list of blog posts, the home.php file is executed; unless there is a front-page.php file, in which case that is executed.

There are templates for posts, pages, tag indexes, category indexes, the 404 page, and more. Most of them are provided by the site’s theme.

For a little more in-depth look at WordPress explained, the full template hierarchy for the front page is displayed below.

Hooking in

The answer to the question “what is WordPress and how does it work?” wouldn’t be complete without explaining plug-ins. Plug-ins can change the HTML that’s rendered on a page, but their code does not live in the template files. Instead, WordPress provides a number of hooks onto which people can hang their own code. 

What is a hook?

Hooks are the foundation of an event-based system for extending WordPress. In other words, a hook is another way in which you can customize the features and functions of your site. Developers can register code to be executed when an event occurs. There are dozens of events developers can hook into, such as wp_loaded, which runs after WordPress is fully loaded, and pre_get_posts, which runs before a database query.

Hooks come in two varieties: action hooks and filter hooks. The difference between them is not important for our entry-level explanation of WordPress. The main takeaway here is that the code associated with hooks can carry out actions and change the HTML that is output. For example, a hook can be used to add a widget to a page.

WordPress plug-ins use hooks to integrate their functionality with the HTML rendering process, and they’re one of WordPress’s major strengths. WordPress would be much less powerful if it didn’t provide a mechanism for developers to extend its functionality.

Summary

So how does WordPress work? One blog article can’t possibly explain everything happening beneath the hood of WordPress. But after reading this guide, you now have a basic understanding of what goes on when someone loads a WordPress site.

To review, WordPress is made up of three main components: a server, a database, and a PHP code interpreter. Once you’ve configured the core WordPress files, a series of template files generates HTML web pages. From there, you can use hooks to add plug-ins that will further build out your site.

For more information on how to optimize your WordPress site, get started with Nexcess managed WordPress hosting today!

Nexcess
Nexcess


Power up your sites and stores with custom-built technology designed to make every aspect of the digital commerce experience better. Make your digital commerce experience better with Nexcess.