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)
- 2019 Social Media Image Sizes Cheat Sheet - December 7, 2018
- Best Godaddy Alternatives for Domain Names or Web Hosting - December 3, 2018
- How to Make an Online Portfolio - November 27, 2018