Understanding Hooks, Actions, Filters & Child Themes in WordPress

As you continue learning WordPress theme development, you’ll frequently hear terms like:
Hooks, Actions, Filters, Child Themes.

These are some of the most important concepts in WordPress because they allow developers to customize WordPress without editing core files.

In this article, we’ll understand them in a simple and beginner-friendly way.


1. What Are Hooks in WordPress?

Your assumption is mostly correct.

Simple Definition

Hooks are a way to:

Change or extend default WordPress behavior

without modifying WordPress core files.


Why Hooks Exist?

Imagine WordPress core code like this:

Load header
Load posts
Load sidebar
Load footer

What if developers want to:

  • Add custom code
  • Modify output
  • Insert ads
  • Add tracking code
  • Change titles
  • Create plugins

Hooks make this possible.


Types of Hooks

WordPress has two main types:

Hook TypePurpose
ActionsPerform something
FiltersModify something

Real Life Example

Think of hooks like charging points in a wall.

WordPress provides hook locations

Developers plug custom code into them

2. What Are Actions?

Your understanding is very close.


Simple Definition

Actions allow you to:

Run custom code when a specific event happens

Common Events

Examples:

  • When page loads
  • When post publishes
  • When theme initializes
  • When footer loads
  • When admin dashboard opens

add_action()

Used to attach your custom function to a WordPress event.

Syntax

add_action('hook_name', 'function_name');

Example

function my_custom_message() {

echo "<p>Hello WordPress!</p>";
}

add_action('wp_footer', 'my_custom_message');

What Happens Here?

When WordPress reaches:

wp_footer

it runs:

my_custom_message()

Output

Before closing </body>:

<p>Hello WordPress!</p>

appears automatically.


What is do_action()?

Your assumption is also mostly correct.


Simple Understanding

do_action() triggers an action hook.

Think like this:

FunctionRole
add_action()Attach custom function
do_action()Trigger event

Example

Inside WordPress core or theme:

do_action('my_custom_hook');

Somewhere else:

function show_notice() {

echo "Notice displayed";
}

add_action('my_custom_hook', 'show_notice');

When do_action() runs:

show_notice() executes

Easy Analogy

do_action() = Doorbell button
add_action() = Person responding to bell

Common Action Hooks

HookRuns When
wp_headInside <head>
wp_footerBefore </body>
initWordPress initializes
wp_enqueue_scriptsLoad CSS/JS
save_postPost is saved

3. What Are Filters?

Your assumption is correct.


Simple Definition

Filters are used to:

Receive data

Modify data

Return modified data

Important Difference

ActionsFilters
Do somethingChange something
No return requiredMust return value

add_filter()

Used to modify existing data.

Syntax

add_filter('filter_name', 'function_name');

Example

function change_title($title) {

return 'Modified: ' . $title;
}

add_filter('the_title', 'change_title');

What Happens?

Original title:

Hello World

Modified output:

Modified: Hello World

Internal Working

WordPress does something like:

$title = apply_filters('the_title', $title);

Your function intercepts and modifies the value.


Important Rule

Filters should always return data.

Wrong:

echo $title;

Correct:

return $title;

Easy Analogy

Filter = Water purifier
Water goes in

Gets modified

Comes out cleaner

Common Filters

FilterPurpose
the_titleModify post title
the_contentModify post content
excerpt_lengthChange excerpt length
body_classAdd body classes

4. Actions vs Filters

| Feature | Actions | Filters |
|—|—|
| Purpose | Execute code | Modify data |
| Returns value? | No | Yes |
| Main functions | add_action() | add_filter() |
| Triggered by | do_action() | apply_filters() |


5. Why Child Themes Are Required?

This is another very important concept.


Problem Without Child Theme

Suppose you edit a theme directly:

style.css
functions.php
header.php

Now theme developer releases update.

After update:

Your changes are lost

because files get overwritten.


Solution → Child Theme

A child theme safely modifies parent theme.


Simple Definition

A child theme:

inherits parent theme
+
allows custom changes safely

Real Example

Parent theme:

astra

Child theme:

astra-child

How Child Theme Works

WordPress loads:

Parent theme files
+
Child theme overrides

Benefits of Child Theme

BenefitExplanation
Safe updatesParent updates won’t remove changes
Cleaner customizationEasier maintenance
Override templatesModify specific files
Add custom CSS/functionsWithout touching parent

Basic Child Theme Structure

mytheme-child/

├── style.css
├── functions.php

Child Theme style.css

/*
Theme Name: My Child Theme
Template: astra
*/

Template must match parent folder name.


Load Parent Theme CSS

Inside child theme functions.php

function child_theme_styles() {

wp_enqueue_style(
'parent-style',
get_template_directory_uri() . '/style.css'
);
}

add_action(
'wp_enqueue_scripts',
'child_theme_styles'
);

When to Use Child Theme?

Use child themes when:

  • Customizing premium themes
  • Modifying parent theme templates
  • Adding custom functions
  • Updating parent theme regularly

When Child Theme May Not Be Needed?

If you are creating your own fully custom theme from scratch, child themes are usually unnecessary.

Because:

You already control the parent theme

Final Understanding

Hooks

Allow developers to extend WordPress safely.


Actions

Run custom code on specific events.

Something happened → run function

Filters

Modify existing data before output.

Take value → modify → return value

Child Themes

Protect customizations from theme updates.

Parent theme updates safely
+
Your custom code remains intact