Hooks In WordPress

10

DEC | 2016

Hooks In WordPress

Hooks in WordPress are mainly used to tie the developer’s code into the WordPress core code base. It is the way for one piece of code to interact with and modify another piece of code. There are two types of hooks exist in WordPress, actions and filters. Actions and filters allow to add your own functionality or to modify the sites behavior by hooking a callback function on to a specific tag in the core code. Hooks are used in both theme & plugin files.

Filter is to modify or get the wordpress data before it is sent to the database or browser. Callback functions for filters will be passed through a variable, modified, and then returned. When you work with a filter, you will receive some piece of data and then, you want to return that data back at the end of your function. When WordPress runs, at a specific time a hook that is triggered and lets you take an action is, Action in WordPress. An action calls another function to run beside it rather than modifying something. At the time of execution of WordPress your callback function will run at a specific point and can perform some kind of task. Sometimes a hook exists as both an action and a filter, or a filter and a function. You will see the real difference with the actual function you call. To remove a hook is quite simple. Use the function that you create to remove it that is for ex. remove_filter or remove_action along with the name of the hook, function, and priority.