5.4Introduction to WordPress development
The essentials in 30 seconds
- Hooks are WordPress's extension mechanism: you insert code without modifying core.
- Action = run something at a given moment; filter = modify data as it passes.
- Custom code goes in the functions.php of a child theme, never in the parent theme or core, and is tested locally.
Running mini-case — a small custom adjustment
Hassan wants to add a "one-of-a-kind piece" note under the price of the creations. Samir first looks for a plugin; none matches exactly. He then writes a small filter in the child theme, tested locally, which adds the note only on the relevant category. He documents the snippet so he can find it later.
Sequel to case 5.3 — after compliance, a little custom code.
1. How hooks work
WordPress is designed to be extended without being modified. The central mechanism is the hook: an anchor point where you attach your code. Actions let you run something at a precise moment (after a post is saved, when an email is sent); filters let you modify data as it passes (a title, a price, a text).
Themes and plugins use these hooks heavily: that is what lets them coexist. Understanding this logic is enough to read a lot of WordPress code and to intervene occasionally, without becoming a developer straight away.
2. Where to put your code
A theme contains templates, styles and a functions.php file where functions are declared. A plugin is a self-contained package that adds features. Samir never touches WordPress core: the next update would wipe everything.
Custom code goes in the functions.php of a child theme (or in a small dedicated plugin), never in the parent. It is tested locally or on staging, commented and backed up. A well-targeted snippet is often better than a big plugin for a very specific need.
🔎 Concrete example — Adding a note to a category (Samir's case)
Need: "one-of-a-kind piece" under the price, creations category.
1. Search for a plugin → none matches.
2. Child theme active.
3. Filter tested locally on the displayed price.
4. Check: creations category only.
5. Commented snippet + backup.
→ No change to the parent theme.
Result: a precise, lasting adjustment.
Lesson: look for the plugin first, code afterwards, always in the child.
Section vocabulary
- Hook
- An anchor point where code is attached to extend WordPress.
Simple example: a filter on the displayed price.
What it is not: modifying WordPress core.
Reflex: extend through hooks, not core.
- Action
- A hook that runs code at a precise moment.
Simple example: sending a notification after publication.
What it is not: confusing action and filter.
Reflex: action = do something at a moment.
- Filter
- A hook that modifies data as it passes and returns it.
Simple example: adding a note to the price.
What it is not: displaying directly without returning the value.
Reflex: filter = modify and return.
- functions.php
- The theme file where functions and hooks are declared.
Simple example: the child theme's file.
What it is not: editing the parent theme's file.
Reflex: custom functions in the child.
- Custom plugin
- A small plugin dedicated to one feature, independent of the theme.
Simple example: a snippet packaged to last.
What it is not: putting everything in the theme at the risk of losing it on a switch.
Reflex: business code can live in a plugin.
In practice — Reading and placing a hook
- Find a hook suited to a small need in the documentation.
- Activate a child theme and open its functions.php.
- Add a simple filter or action, tested locally.
- Check the result, comment the snippet and back it up.
Ready-to-use script — explaining custom work (25s)
"For a very specific need, I can add a small piece of code in a child theme, without touching WordPress core. It is tested separately and kept through updates. For everything else, we favour a proven plugin."
Show caution: plugin first, code afterwards.
Copy-paste template — snippet sheet
NEED: _______________
EXISTING PLUGIN TESTED: yes / no
HOOK USED: action / filter
FILE: child theme functions.php
TESTED LOCALLY / ON STAGING: yes / no
COMMENT IN THE CODE: yes / no
SNIPPET BACKUP: yes / no
Small adjustment
A targeted filter in the child theme.
Business feature
A small custom plugin, independent of the theme.
Learning
Test hooks locally on a demo site.
Team
Version the code and document every snippet.
✓ Best practices
- Look for a plugin before coding.
- Always go through the child theme.
- Test locally or on staging.
✗ Common pitfalls
- Modifying WordPress core.
- Pasting code into the parent theme.
- Leaving an untested snippet in production.
Key takeaways
- Hooks extend WordPress without modifying core.
- Action = run; filter = modify data.
- Code goes in the child's functions.php.
- You test locally and document.
48h Challenge — apply tomorrow
Find a simple hook in the documentation, add it to a child theme and check the result locally. Comment the snippet. 30 minutes.
- I distinguish actions and filters.
- I place my code in a child theme.
- I test and document a snippet.
Frequently asked questions
Do I need to learn PHP to develop on WordPress?
Yes, PHP is the language of WordPress, along with HTML, CSS and JavaScript as needed. You can start with small hooks without being an expert, then go deeper if development appeals to you.
Existing plugin or custom code?
Always look for a proven plugin first: less maintenance and tested by many sites. Custom code is justified when no plugin fits or for a very specific need, with a targeted snippet rather than a big plugin.
Where can I test my code safely?
Locally or on a staging site, with a child theme. Never directly in production on the client's site. Back up first and keep a record of the snippet.
What is a hook in WordPress?