5.4 · Introduction to WordPress development

Level 5 · Maintenance, advanced security & development

5.4Introduction to WordPress development

Goal: understand how hooks work and know where to place a small piece of code without touching WordPress core.
Estimated time: 20 min · self-paced reading · If you only have 5 min: read “The essentials in 30s” + the diagram.

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.

Common misinterpretation: "I can paste my code into the parent theme's functions.php". No: the next theme update will wipe the file. The child theme (or a home-made plugin) is the safe place.
Extending WordPress with hooks WordPress triggers an event, a hook calls your code placed in the child theme. WordPressevent+Hookaction/filter+Code inthe child+Modifiedresult A hook attaches your code at the right moment; the code lives in the child theme.
The hook principle: an anchor point, code in the child theme.
Text version of the diagram (SEO / screen readers / translation): 1) WordPress triggers an event. 2) A hook (action or filter) calls your code. 3) The code is placed in the child theme. 4) The result is displayed. Lesson: extend without modifying core.

🔎 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

  1. Find a hook suited to a small need in the documentation.
  2. Activate a child theme and open its functions.php.
  3. Add a simple filter or action, tested locally.
  4. Check the result, comment the snippet and back it up.
A first hook understood and placed in the right spot, with no risk to the parent theme.

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.

Section exit checklist
  • I distinguish actions and filters.
  • I place my code in a child theme.
  • I test and document a snippet.
Self-rating 1-5: do I understand the principle of a hook?is my code in the right place?

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.

Check your understanding

What is a hook in WordPress?

Additional resources (optional, to go further)

Level 5 examFresh, harder questions to test what you've learned