Determining the correct hook. At the time of creating this lesson,
WordPress Core has more than 3,000 available hooks.
As you might guess, there is a hook for everything. So one problem you may often
encounter is which is the correct hook to use for a given set of functionality.
In this lesson, you will learn how to find the right hook for your needs,
as well as some of the more important hooks to be aware of.
The first choice to make is whether you're going to need an action or a filter hook.
As a reminder, actions allow you to perform some action at a specific point
during the execution of a request, while filters allow you to modify or filter some data
at a specific point, which will be used later on.
You will need to determine whether you just need to trigger something
or if you need to modify some data.
There are a couple of places you can find a list of available hooks in the WordPress documentation.
There is a section dedicated to hooks in the Common APIs Handbook of the WordPress Developer
documentation. From there, you can navigate to the action or filter reference
and then browse through the list of actions or filters run during a typical request.
While this list is not extensive, it is a good starting point to find the hook you need.
It is also possible to find a list of all WordPress hooks in the WordPress code reference
under hooks. Then from there, it is possible to either navigate manually
or search for hooks using the search bar.
Many of the available core hooks are not regularly used, if at all, by plugin developers,
while some are used more often than others. Let's look at some of the most important hooks
to remember. The plugins loaded hook. This hook fires once all plugins are loaded.
This hook is the perfect one to use when you want to register any plugin initialization tasks,
as it will ensure that all other plugin code will be loaded.
This helps if you need to check for third party compatibility or if your plugin relies
on another plugin's logic to execute. The Annette hook. This hook is executed when the core of
WordPress is loaded. This is usually the hook you use to configure the core functionality of your
plugin, such as registering custom post types, dashboard menus or cron tasks.
A similar hook called admin Annette exists to register core functionality, but only for
WordPress admin pages. The WPNQ scripts hook. When you need to NQ CSS style files or JavaScript files,
this is the hook to use. Inside the hook callback function, you can use the WPNQ style and WPNQ
script functions to NQ styles and scripts. But what about hooks registered outside of WordPress core?
If you need to extend the functionality of another plugin or theme,
you will have to rely on what hooks the plugin or theme developer has put in place.
In many cases, there will be a limited set of hooks to make use of,
and they may not even be documented correctly. A good place to start is to search for any
instances of do action and apply filters inside their code base to find any hooks available.
Additionally, some developers have documentation on their site,
which includes all the relevant hooks you can use.