Saturday, October 24, 2026The WordPress PlaygroundFacebookXPinterest
Glossary

Action Hook

An action hook is a point in WordPress where you can run your own function at a specific moment. For example, you can use one to add code to the footer, send an email after a post is published or load a stylesheet on every page.

Actions are one of the two types of WordPress hooks, and filters are the other. In this article, we will see how action hooks work with a simple example.

How Does an Action Hook Work?

While WordPress builds a page, it calls do_action() at important moments. Each call has a name, such as init, wp_head or wp_footer. When WordPress reaches that line, it runs every function attached to that name.

It works just like an alarm clock. You set it for a certain time, and when that time comes, your task starts automatically. You set this alarm with the add_action() function.

A Simple Action Hook Example

Here is a small snippet that prints a thank-you line at the bottom of every page:

function wpt_footer_note() {
    echo '<p>Thanks for visiting our site.</p>';
}
add_action( 'wp_footer', 'wpt_footer_note' );

The first value in add_action() is the hook name, and the second is your function name. You can also pass a priority, which is 10 by default, and the number of arguments your function accepts.

Common Action Hooks in WordPress

  • init runs once WordPress has loaded and is used to register post types and taxonomies.
  • wp_enqueue_scripts is the right place to load CSS and JavaScript files on the front end.
  • save_post runs whenever a post is created or updated.
  • wp_head and wp_footer let you add code to the head section and the footer.

To load scripts the proper way, read our guide on how to add JavaScript in WordPress.

Tip

An action function doesn't need to return anything. If you want to change a value, such as a title or some text, use a filter hook instead.

Put your snippets in a child theme's functions.php file or a small custom plugin. I always test new hook code on a staging site first.

Now you know how action hooks work. Write your first one, and the idea will click. If you get stuck, ask us in the comment section below.