WordPress is a large PHP application. Every page you see on a WordPress site is built by PHP code running on the server, using the same ideas you have learned in this course: functions, arrays, classes, sessions and cookies, and a database.
The three parts
| Part | What it is | Where |
|---|---|---|
| Core | The WordPress software itself | wp-admin/, wp-includes/, root files |
| Themes | PHP templates and styles that decide how the site looks | wp-content/themes/ |
| Plugins | PHP code that adds features | wp-content/plugins/ |
You never edit core. You extend WordPress with themes and plugins, using hooks (see WordPress Hooks).
What happens on a request
- The web server receives a request and, through rewrite rules, sends it to
index.php. index.phploadswp-blog-header.php, which loadswp-load.phpandwp-config.php.wp-config.phpdefines the database settings and constants.- WordPress connects to MySQL, loads active plugins, then the theme’s
functions.php. - It runs
initand other hooks, parses the URL and decides what content was asked for (a post, a page, an archive, a search). - It runs a query and chooses a template from your theme.
- The template prints HTML using functions such as
the_title()andthe_content(). - PHP sends the page to the browser.
It is the same flow as How PHP Works, with a lot of machinery in the middle.
The WordPress style of PHP
WordPress began in 2003 and is backwards compatible, so its style looks different from modern frameworks:
- Many global functions with a
wp_prefix or a plugin prefix (wp_enqueue_script,get_option). - Global variables such as
$postand$wpdb. - Hooks (actions and filters) as the main extension mechanism.
- Its own coding standards: tabs for indentation,
snake_casenames, spaces inside brackets. - Classes exist (
WP_Query,WP_Post,WP_User) and are used more and more.
Modern plugin code can still use namespaces, typed classes and Composer inside a plugin.
Checking that WordPress is running
<?php
echo defined("ABSPATH") ? "WordPress is loaded\n" : "not loaded\n";
echo function_exists("add_action") ? "hooks are available\n" : "no hooks\n";
echo is_string(get_bloginfo("name")) ? "site name is a string" : "unexpected";
WordPress is loaded
hooks are available
site name is a string
(That example was run inside a real WordPress installation.)
Version and requirements
WordPress needs a minimum PHP version, and recommends newer ones. Requirements change with each release, so check the official page before choosing a host: wordpress.org/about/requirements. Running a supported PHP version matters for security (see PHP Versions).
<?php
echo is_string(wp_get_wp_version()) ? "WordPress " . (version_compare(wp_get_wp_version(), "6.0", ">=") ? "6.0 or newer" : "older than 6.0") : "";
WordPress 6.0 or newer
What PHP skills carry over
| This course | In WordPress |
|---|---|
| Functions | Template tags, hook callbacks |
| Arrays | Settings, query arguments, post meta |
| Include and require | Theme parts, plugin files |
| OOP | WP_Query, widgets, modern plugin architecture |
| Security | Escaping, nonces, $wpdb->prepare() |
| Sessions and cookies | WordPress uses its own login cookies |