How to Create Custom add_action Hooks in WordPress

WordPress is based on Hook-System .WordPress Have Lot of Predefined hooks line.

add_action("init" ,'Function name');
add_action( 'muplugins_loaded', 'plugin_override' );
add_action( 'wp_loaded', 'your callback function' );
add_action( 'the_post', 'he_post_action' );

Suppose we need to create over own hook here what we can do it

add_action('hook_name' ,'hook_function');

By Using the add_action We can Create a Custom Hook first argument is the name of the hook “hook_name” and Second argument is the what we need to happen when we call this hook “hook_function”

function hook_function(){
 
  echo "welcome to  Wpdadd hooks";
}

To call this Hook we need to user

do_action('hook_name');

Suppose if we need to Override the hook first we need to remove the hook

remove_action('hook_name', 'hook_function');

To add new functionality we can create new hook function

add_action('hook_name', 'new_hook_function');
 
function new_hook_function(){
 echo "New Hook of Wpdadd";
}

Add a Comment

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

2 × 3 =