Hooks

Hooks are a way for one piece of code to interact/modify another piece of code at specific, pre-defined spots. They make up the foundation for how plugins and themes interact with WordPress Core.

There are two types of hooks: Actions and Filters. To use either, you need to write a custom function known as a Callback, and then register it with a WordPress hook for a specific action or filter.

The main difference between an action and a filter can be summed up like this:

  • an action takes the info it receives, does something with it, and returns nothing. In other words: it acts on something and then exits, returning nothing back to the calling hook.

  • a filter takes the info it receives, modifies it somehow, and returns it. In other words: it filters something and passes it back to the hook for further use.

Said another way:

  • an action interrupts the code flow to do something, and then returns back to the normal flow without modifying anything;

  • a filter is used to modify something in a specific way so that the modification is then used by code later on.

Last updated