Saturday, October 24, 2026The WordPress PlaygroundFacebookXPinterest
Glossary

Hooks

Are you wondering how plugins change WordPress without editing its core files? They use hooks. Hooks are specific points in the WordPress code where you can attach your own functions, either to run extra code or to change data.

Once you understand hooks, most theme and plugin code becomes much easier to follow.

What are Hooks in WordPress?

Every time WordPress loads a page, it goes through many stages. It starts up, loads plugins and the theme, fetches posts, prints the header, shows the content and finally prints the footer. At many of these stages, WordPress leaves a hook that says, "If anyone wants to do something here, now is the time."

Think of hooks like bus stops on a fixed route. The bus always stops there, and your code can get on at the stop it needs.

The Two Types of WordPress Hooks

  • Actions let you do something at a certain moment, such as adding a script to the footer or sending an email when a post is published. You attach them with add_action().
  • Filters let you change data before WordPress uses it, such as a post title or the excerpt length. You attach them with add_filter().

WordPress runs actions with do_action() and filters with apply_filters(). Plugins and themes can create their own hooks too, so other developers can extend them in the same way.

Why Should You Care About Hooks?

Hooks are the reason you never need to edit WordPress core files. Changes to core files are wiped out with every update, but code attached to hooks keeps working. Almost every plugin you install depends on them.

Each hook also accepts a priority number. By default, it is 10, and lower numbers run earlier. This helps when two functions use the same hook and one must run first.

Note

Put your hook code in a child theme's functions.php file or in a small custom plugin. Code added to a parent theme is lost when that theme updates.

[/notice]

To go deeper, see our plugin development overview.

So, that's how hooks work behind the scenes. Learn the difference between actions and filters, and the rest will fall into place. Do let us know in the comment box below if anything is unclear.