Chapter 3. Hooks


  • Creating actions for action hooks

  • Creating filters for filter hooks

  • Using hooks within a PHP class

  • Adding custom hooks to plugins

  • Finding hooks within WordPress

Hooks are the backbone of WordPress. They enable plugin developers to "hook" into the WordPress workflow to change how it works without directly modifying the core code. This enables users to easily upgrade to newer versions of WordPress without losing modifications.

If a developer modified the core code, those edits would be lost the next time WordPress was updated. The update would overwrite all those changes. Using hooks enables you to develop plugins in separate folders apart from the core, keeping the plugin code safe from updates.

Without hooks, plugins would have no way to modify how WordPress works. The hooks system you learn about in this chapter is used throughout the book and is something you will use in nearly every plugin you create. After you learn how to use hooks, you will understand exactly why WordPress is such a powerful platform and has thousands of plugins built for its millions of users.

WordPress has two primary types of hooks: action hooks and filter hooks. The former enables you to execute a function at a certain point, and the latter enables you to manipulate the output passed through the hook.


Hooks aren't just for plugins. WordPress uses hooks internally. If you browse through the core source code, you can see many examples of how WordPress uses its own system ...

Get Professional WordPress® Plugin Development now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.