Why WordPress Runs on PHP
WordPress is, at its core, a large PHP application. Every theme, every plugin, every admin screen is PHP code running on the server, building the HTML page that gets sent to a visitor's browser. You don't need to become a PHP developer to run a WordPress site — but knowing the basics turns "mysterious code I'm scared to touch" into something you can read and edit with confidence.
PHP files are mostly regular text, with special tags marking where the PHP code starts and stops. Everything outside those tags is treated as plain HTML.
- ✓PHP code lives inside
<?php ... ?>tags, mixed directly into HTML files. - ✓WordPress itself, every theme, and every plugin are written in PHP.
- ✓You don't need mastery — just enough to read and make small, safe edits.
The Building Blocks
A handful of concepts cover almost everything you'll encounter in WordPress theme and plugin files.
A named container for a value, always starting with a dollar sign, like $title.
A named, reusable block of code that runs when called, like get_the_title().
An if statement that runs code only when a condition is true.
Code that repeats — WordPress's own "The Loop" runs once per post being displayed.
Variables hold data, functions act on that data, conditionals decide what to show, and loops repeat the process for each item.
A Function From functions.php
<?php function my_custom_greeting() { $name = 'Reader'; if ( is_user_logged_in() ) { $name = wp_get_current_user()->display_name; } echo 'Welcome, ' . $name; }
A variable holds the default name, a conditional checks if someone is logged in, and the function prints the result.
Editing functions.php Safely
function, a name, and parentheses.{ } and end each line with a semicolon.add_action() or add_filter().Where Should You Edit PHP?
Common PHP Mistakes
Breaking Down What You Just Learned
WordPress is PHP underneathEvery theme, plugin, and admin screen is built from PHP code.
Four core building blocksVariables, functions, conditionals, and loops cover most WordPress PHP.
Functions get hooked inadd_action() and add_filter() connect custom functions to WordPress.
A code editor beats editing liveSFTP with a local editor avoids the built-in editor's lack of undo.
Small mistakes cause fatal errorsMissing semicolons and mismatched braces are the most common culprits.
Try It Yourself
Add a function to your child theme's functions.php that changes the site's default excerpt length. Search for the excerpt_length filter and hook a simple function into it.
Write Your First Custom Function
Getting comfortable inside functions.php
By the end of today, your child theme should include one working custom function you wrote yourself.
- Set up a local code editor and connect to your site via SFTP.
- Open your child theme's functions.php file.
- Write a simple function using a variable and a conditional.
- Hook it into WordPress with
add_action()oradd_filter(). - Save, upload, and reload the site to confirm nothing broke.
Recap
A named container for a value, starting with a dollar sign.
A reusable, named block of code that runs when called.
Hooks a custom function into a specific point in WordPress.
A syntax mistake, like a missing semicolon, that can break the whole site.
Key Takeaways
- WordPress, its themes, and its plugins are all built from PHP code.
- Variables, functions, conditionals, and loops cover most of what you'll encounter.
- Custom functions connect to WordPress through
add_action()andadd_filter(). - Editing locally with SFTP is safer than the built-in theme editor, which has no undo.
- Missing semicolons and mismatched braces are the most common causes of a broken site.