How Do WordPress Hooks, Actions and Filters Work? – WPQuickies

I often get asked how to change the way WordPress outputs some data or how to change the way WordPress core operates.

Aha – you need to learn about WordPress Hooks: Actions and filters!

What Are WordPress Hooks?

Hooks allow you to interact and modify WordPress core functionality and are used by plugins, themes and the WordPress core itself.

The official documentation about hook is at

How WordPress Works

WordPress is an event-driven PHP application.

So for a process such as “Update Post” there will be a series of events that run chronologically to complete the process. 

WordPress is an event-driven app

The events run WordPress core functions that complete the outcome of the event.

As a theme or plugin developer, you may want to run your function before, during or after the event to do something or alter how WordPress does something.

Some but not all of these functions have an associated hook that you can link to your callback function.  When the hook gets called, your custom function is run.

More than one function can be linked to a hook.

Types Of Hooks

There are two types of hooks you can use in WordPress development. Actions and Filters.

WordPress actions and filters, WordPress Hooks

Actions run a function when the hook is fired. The callback function runs inside the scope of the hook and has access to WordPress global variables and any available object data within the scope. 

Actions can change the way WordPress works at that point in the event. Actions don’t have to have any data passed to them.

Filters receive some parameter data, run a function when the hook is fired, and returns the parameter data to WordPress, allowing the developer to intercept and modify the data being passed back to WordPress.

Actions are usually reserved for notable changes to how WordPress works – adding options, popping up a dialogue box, creating custom post types, processing payments etc.

Filters are usually reserved for modifying data in transit to the following process or event.  Filters operate more subtly than actions.

Action Hooks In Core PHP Code

In the WordPress code, actions are hooked using the do_action function in this format:

do_action( 'action_name', [optional_arguments] );


The do_action( ‘wp_head’ ); action can be hooked in to run custom code every time WordPress processes the site header.

Adding An Action Hook Callback Function

You can add the code in your plugin, the theme’s functions.php file or using a code snippets plugin.

Add your action callback function using the following format:

add_action( 'hook_name' , 'callback_function_name'  , $priority=10 , $num_arguments=1 );


function noindex(){
  echo '<meta name = "robots" content = "noindex, nofollow">
add_action( 'wp_head', 'noindex' );

Filter Hooks In Core PHP Code

In the WordPress code, actions are hooked using the apply_filters function in this format:

apply_filters( 'filter_name', 'value_to_be_filtered' , [optional_arguments] );


The apply_filters( ‘admin_footer_text’, string $text ); filter can be hooked in to modify the text displayed in the admin footer. “Thank you for creating with WordPress.”

Adding A Filter Hook Callback Function

In the WordPress code, actions are hooked using the apply_filters function in this format:

add_filter( 'hook_name' , 'callback_function_name'  , $priority=10 , $num_arguments=1 );


function my_admin_footer_text( $footer_text ){
  return '<p>Powered by Zero Point Development</p>';
add_filter( 'admin_footer_text', 'my_admin_footer_text' );

Action and Filter References




That’s my quick guide to WordPress hooks, actions and filters.

Do you still have questions about WordPress hooks, actions and filters?

Ask in the comments below.


Join me every Thursday at 1 pm Sydney time for some more WPQuickies – WordPress tips and tricks in thirty minutes or less.

Broadcasting live on YouTube and Facebook.

Suggest a #WPQuickies Topic

If you have a WordPress topic you want to see explained in 30 mins or under, fill out the form below.

Watch Previous WPQuickies

Was this article helpful?

Leave a Comment

Your email address will not be published. Required fields are marked *

Keep In Touch With My Weekly Blog Email

A once-per-week daily digest of my posts from the week. No sales, no spam and I will not share your details with anyone else.


Wil is a dad, WordPress consultant, WordPress developer, business coach and mentor. He co-organizes the WordPress Sydney meetup group and has been on the organising committee for WordCamp Sydney since 2014. He speaks at many special events and contributes to the WordPress open source project. His likes are chillies, craft beer and electrogravitics.