WordPress Development
WordPress development means changing or extending WordPress with code. You can build your own theme (the design), your own plugin (a feature), or use WordPress as an application platform with the REST API. This section of the tutorial teaches theme development, and then the plugin and REST API sections follow.
What you should know first
- HTML and CSS: for the design of the theme.
- PHP basics: variables, functions, arrays, loops and classes. If you are new, read the PHP Tutorial of this website first.
- Basic MySQL knowledge: helps to understand how WordPress stores the data. See WordPress Database.
- Basic JavaScript: for the block editor and interactive features.
Tools for a developer
| Tool | Use |
|---|---|
| Local server (Docker, XAMPP, Local) | A WordPress site on your own computer |
| Code editor (VS Code, PhpStorm) | Write the code, with PHP and WordPress hints |
| WP-CLI | Run the WordPress commands, scripts and tests |
| Git | Version control for your theme or plugin. See the Git Tutorial |
| Query Monitor plugin | Shows queries, hooks and errors |
| WP_DEBUG | See PHP errors. See WordPress Debugging |
What you will learn in this section
| Topic | Chapter |
|---|---|
| Theme files and functions | Theme Files and Functions |
| Which template WordPress picks | Template Hierarchy |
| CSS and JavaScript in themes | Enqueue Scripts and Styles |
| Show posts | The Loop and WP_Query |
| Conditions in templates | Conditional Tags |
| Widget areas and menus | Register Sidebar and Register Nav Menus |
| Hooks | Actions and Filters |
| Shortcodes | Shortcode API |
| Your own content types | Custom Post Types, Custom Taxonomies and Custom Fields |
| Safe customization | Child Theme |
| Modern themes | Block Themes and theme.json |
Your first line of WordPress code
WordPress calls a hook at many places while it builds a page, and your code can attach to it. This is the main idea of WordPress development. Here we attach a function to the wp_footer hook. A file in wp-content/mu-plugins is loaded automatically, so we use it for a quick test:
<?php
add_action( 'wp_footer', function () {
echo '<p>Hello from my first WordPress code!</p>';
} );
$ curl -s http://example.com/ | grep -o "<p>Hello from[^<]*</p>"
<p>Hello from my first WordPress code!</p>
The line of text is on the page now, and we did not touch any theme file. You will use this pattern in every chapter.