Saturday 21 November 2015

Types of Action and Filter Hooks

The WordPress Codex has two important pages that can help you orient yourself with what hooks are available in WordPress.

NOTE: At the time of writing there is a bit of a transition of documentation on hooks from the Codex to the Code Reference site. Because of this you may find hooks that are listed on the Codex, but not documented. You should be able to find some documentation for all of the hooks if you search for them in the Code Reference, however, it does not have any current pages like the Codex where all hooks are grouped in one place.
The WordPress Action Reference page has available actions listed by the following categories:
The Codex also has a similar Filter Reference page, which it lists by the following categories:
Many of these filter hooks are separated into subcategories: Database Reads and Database Writes. This depends on whether you are reading from the database prior to displaying on a page or editing a screen, or you are writing code prior to saving data to the database.
Working with hooks in WordPress starts with figuring out what hook you need to tie your code into and then writing the code to modify the data you need or run whatever action you need.
If you get stuck or you are not sure which hook to use, you can usually figure it out by searching for something like: “WordPress action for [whatever you want to hook into].”  The WordPress StackExchange has a number of results with questions like this as well.

1 comment:

Popular Articles