- The do_action function finds out about the functions it should include by a sibling function named add_action, which creates a list of all functions. You can thing of add_action as the boss and do_action as the worker. This function, like its sibling, is a predefined function in WordPress, so you only need to call it. This function call is often included next to the function definition its mentioning. The following is an example of defining my_new_code and asks WordPress to hook it on:<?phpfunction my_new_code($name) {echo “Hello ” . $name;}add_action(’the_location’, ‘my_new_code’);?>
- You can "add_action" all you like, but until you "do_action" nothing is going to change.
say you had these functions in functions.phpfunction function1() { echo "Hello "; }function function2() { echo "John!"; }
You could simply add them to the init functionadd_action('init', 'function1');add_action('init', 'function2');
And they will display at the top of your page without you specifically calling "do_action" because Wordpress is already going to "do" 'init' upon initialization.
But if you add them to something that does not already exist...add_action("doit", "function1");add_action("doit", "function2");
Nothing will happen until you "doit"
do_action('doit');
Link For Refe: Link
NOT: To say it briefly,
add_action/add_filter are for registering the action/filter to WordPress
do_action/do_filter are for applying that registered action/filter
add_action/add_filter are for registering the action/filter to WordPress
do_action/do_filter are for applying that registered action/filter
What is the diff between do_action and add_action in wordpress ?
Reviewed by Md Shahinur Islam
on
January 04, 2018
Rating:
No comments: