Register a Custom Hook and use it in WordPress

In WordPress, we have the option to register a custom hook for our use. For this, we have “do_action();” which register a hook in WordPress.

do_action(‘custom_hook_name’,$parameters);

you have right above code line to register a hook. you can choose you to hook name and parameters which you want to pass in that hook. Hook name should be unique.

How to use this hook ?

For using this hook we have another function is “add_action();” in this function we need to specify the hook name in which you want to perform the action and the function name in which we’ll write our performing code.

add_action(‘custom_hook_name’,’custom_function’,10,1);

10 is the priority of action and 1 is the no of a parameter which you wanna get via this hook.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s