The final vital component in a WordPress plugin is the hook, which defines when the plugin is executed. This is arguably the most confusing component of a plugin, so we will be thorough in our explanations. Just as in pop-music, the term "hook" is sometimes ambiguous—different people use the term to refer to different things. Technically, the term "hook" should refer to a WordPress event, such as get_header
or the_content, but sometimes it is used generally to refer to the add_action()
or add_filter()
functions which reference the hook. Pay attention to the context, and it should be clear which meaning was intended. The most important thing to understand here is that you determine when your functions execute by attaching them to a WordPress event by using the add_action()
or add_filter()
functions. Remember: hooks are events.
The syntax for both functions is exactly the same. We'll discuss the reasoning for this shortly, but for now, just...