Hooks are provided by WordPress and are used to modify or add functionality to the core system of WordPress.
Like the term ‘hook’, WordPress hook allow our plugin to ‘hook into’ the WordPress. It is a certain location in the WordPress code which allows us to attach or run our own code.A Hook is a generic term.

WordPress hook are of two types

1) Action Hooks
2) Filter Hooks

Action Hooks

An Action hook in WordPress is a hook that is fired at specific time during execution. In other word action fired when a specific events occur in wordpress. lets us take an action.

Action hooks allow us to add our own code to the WordPress core to achieve some new functionality. Action hooks helps to modify theme and pluginsĀ as per our requirement.

A generic way of representing an action hook is:

do_action($name, $args)

$name = the name of the action hook

$args = optional parameter(s) passed to functions written by us which register with the particular action hook. Action hooks can have parameters or no parameter at all .
for example do_action('wp_head') this hook has no parameter

How to hook an action into wordpress :
To add a action hook is quite simple. the below example shows how to add an action hook

add_action( 'action_hook', 'your_function_name' );

 add_action( 'wp_head', 'add_meta_desctiption' );
function add_meta_desctiption() {
echo '';

Filter Hooks

Filter hooks are WordPress hook that allows us to manipulation of text and other output.

Or simply a filter hook allows us to get and manipulate WordPress data before it sent to the database or to the web browser.

A filter hook can be recognized as :

add_filter ( 'hook_name', 'our_filter', [priority], [accepted_args] );

hook_name = name of the hook want to register
our_filter= the name of your filter
priority =it helps in setting the priority of the hook or order of our filter should be applied. if no value defined it will take default value 10
accepted_args optional parameter(s)= the argument defining how many arguments our function can accept.default value 1,

Leave comment

Your email address will not be published. Required fields are marked with *.