Hook, in general, is a tool with a curved portion which can be used to hold another object. It conveys the act of hooking any material in it. One end of the hook is pointed, so that this end can pierce another object, which is then held by the curved part.

In WordPress, hook refers the location which allows users to attach or run their own code without modifying the original files. It allows the user to change the functionality of a program beyond the modification of the core WordPress code. These codes are implemented through the various themes and plugins to hook the additional features. Modifying the core system is not a good option to change the default output. Instead, hooking own code up into the original code is a better way to add the functionality in a system.

Hooks can be categorized in two types – Action Hooks and Filter Hooks.

Action Hooks

Actions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. Also, actions are events when certain things have occurred, certain resources are loaded, certain facilities are available and how early the action has occurred in the WordPress.

Action hooks are designated points in the WordPress core, theme and plugins code where it is possible for outside resources to insert additional code and customize the code to do additional functions they may desire. They allow to execute custom functions which are referred to as actions and to add additional code to the WordPress core or theme so that new functionality or customization can be achieved. 

Functions of Action Hooks

Add Action

Add action hooks a function on to a specific action. It is a function which hooks user’s action to the core action hook. An example is commonly used wp head action hook. Wp head action hook is used by many themes and plugins to inject additional CSS stylesheets, processing code or anything else required to sit between the <head> and </head> tags of WordPress theme’s XHTML structure. 

Do Action

This function executes functions hooked on a specific action hook. When the action is called, all functions that are ‘hooked’ to this action will get executed.

Has action

This function checks if any action has been registered for a hook.

Do action ref array

This function executes the function hooked on a specific action hook, specifying arguments in an array.

Did action

This function retrieves the number of times an action is fired. 

Remove action

This function removes a function attached to a specified action hook

Remove all actions

This function removes all of the hooks from an action.

Doing action

This function checks if an action is currently being executed. 

Filter hooks

Filters are the functions that WordPress passes data through, at certain points in execution, just before taking some action with the data. Filter are primarily responsible for intercepting, managing and returning data before rendering it to the browser or saving data from the browser to the database.

Filter hooks are another type of WordPress hook that are used to manipulate the output. Filter hooks can also be used for truncating text, changing formatting of content or manipulating any other programming. A filter can be used to modify content before WordPress uses it. Filters sit between the database and the browser when WordPress is generating pages and between the browser and the database when WordPress is adding new posts and comments to the database. Most input and output in WordPress passes through at least one filter.

Functions of Filter hooks

Add filter

This function hooks a function or method to a specific filter action.

Apply filter

This function calls the function added to a filter hook. The function allows for additional arguments to be added and passed to hooks. The apply filter hook will always pass a parameter to the filter which is the customized function written by user.

Has filter

This function checks if any filter has been registered for a hook.

Apply filters ref array

This function executes the function hooked on a specific filter hook, specifying arguments in an array.

Current filter

This function retrieves the name of the current filter or action.

Doing filter

This function checks if a filter is currently being applied.

Remove filter

This function removes a function attached to a specified filter hook. This method can be used to remove default functions attached to a specific filter hook and possibly replace them with a substitute.

Remove all filters

This function removes all of the hooks from a filter.

This is how a user uses the hooks to effectively change the working procedure of WordPress by adding hooks of their own to the plugins and themes.