What is the diff between do_action and add_action in wordpress ?

What is the difference between do_action and add_action functions in wordpress. I have read about them, but I have a confusion:: I feel that add_action is mandatory for adding functions to a location, then only we can call do_action to call those functions. We can not call do_action without addding any functions to an action. Am I right or not ?

Also I am working on a wordpress project for the first time.

I have a lot of do_action calls in header.php file and if I remove do_action calls, I can not see any effect on the browser output. Also I cannot find the corresponding add_action calls for those do_action calls in my project.
LVL 2
puneetdudejaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NeoAshuraCommented:
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:

<?php

function my_new_code($name) {

echo “Hello ” . $name;

}

add_action(’the_location’, ‘my_new_code’);

?>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gwkgCommented:
You can "add_action" all you like, but until you "do_action" nothing is going to change.

say you had these functions in functions.php

function function1() { echo "Hello "; }
function function2() { echo "John!"; }

You could simply add them to the init function

add_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');

0
gwkgCommented:
Heres a list of all the existing actions you can "add_action" to

http://codex.wordpress.org/Plugin_API/Action_Reference
0
link2caroCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.