Hooks are the WordPress equivalent of APIs, short pieces of code that interact with another piece of code. The difference, however, is that hooks in WordPress only ever interact inside of the same WordPress installation and not via the internet with a third-party site.
Hooks can request information, modify data, add data, or delete information. In WordPress, hooks can be used with themes, plugins, or to modify the core functionality of WordPress itself.
If you’re new to WordPress, then you won’t have to ever worry about what hooks are or how they function. Hooks, however, are how WordPress developers allow plugins, themes, and other core functionalities to interact with other pieces of code using something called a Callback.
Specifically, hooks in WordPress come in two flavors: actions and filters.
Actions, just as you might expect, are a specific kind of hook that cause something else to happen. For example, if a user on your site leaves a comment, it’s a hook that takes this information and then writes it in the database.
Filters, on the other hand, allow for information to be changed. For example, if you create a new post, your WordPress site may be set up to automatically create a permalink that includes the date that the post was written. This is an example of a filter hook in action.
Perhaps the easiest way to think of an Action is, “If X happens, then do Y.” A filter, on the other hand, is more like, “When X happens, then do Y.”
WordPress comes built-in with a number of hooks, but it is also possible to create your own using the PHP scripting language. The syntax for writing hooks is identical for both actions and filters even though they operate somewhat differently.
Latest posts by Jamie (see all)
- How to Add a Horizontal Line to a WordPress Post or Page - February 18, 2019
- How to Add a Contact Form to Your WordPress Website or Blog - February 12, 2019
- What Is A Parked Domain? – Guide To Parked Domain Names - January 18, 2019