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

ToolUse
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-CLIRun the WordPress commands, scripts and tests
GitVersion control for your theme or plugin. See the Git Tutorial
Query Monitor pluginShows queries, hooks and errors
WP_DEBUGSee PHP errors. See WordPress Debugging

What you will learn in this section

TopicChapter
Theme files and functionsTheme Files and Functions
Which template WordPress picksTemplate Hierarchy
CSS and JavaScript in themesEnqueue Scripts and Styles
Show postsThe Loop and WP_Query
Conditions in templatesConditional Tags
Widget areas and menusRegister Sidebar and Register Nav Menus
HooksActions and Filters
ShortcodesShortcode API
Your own content typesCustom Post Types, Custom Taxonomies and Custom Fields
Safe customizationChild Theme
Modern themesBlock 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>';
} );
Terminal output

$ 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.

Note: Never code on a live site. Work on a local copy or a staging site, and use a child theme or your own plugin, so your changes are not lost on updates. Next: WordPress Theme Files and Functions.

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
Create a post and a page with WP-CLI
Add categories, a child category and a tag to a post
Change the site title and tagline and check them on the site
Set a static front page and a posts page
Create two users and compare their capabilities
Change the permalink structure and print a post URL
Create a navigation menu with three links
Interview Questions & Answers
What is WordPress?
In what year did WordPress come out?
How many default tables are in a WordPress database?
Where is the WordPress content stored?
What is the default table prefix for the WordPress database?
What are the popular plugins in WordPress for SEO?
What is a WordPress theme?