0

This question already has an answer here:

Sorry for making duplicate Topic but it is very important to me because i don't understand this topic by looking other related topics. Actually i am in process to build a WordPress theme and i am working on it, when i look into other themes source codes usually i find this code.

etc etc.

and i understand its something related to do_action();

So my question is that why we use this function in wordpress? and what is the job of this function and can we have a benefit of using this code on every starting and ending html tags in theme?

Thanks in Advance, Regards aran

marked as duplicate by cybmeta, Pieter Goosen, Howdy_McGee, birgire, mrwweb Apr 9 '15 at 4:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

It's actually used by WP to allow plugin developers change WP behavior. You can make your code flexible using do_action so other plugin/theme developers or simply yourself can change behavior of your code.

For example imagine you have a WP loop in a theme framework. You would like to add breadcrumb at the top of it, here is the simplest method:

...
<?php print_breadcrumb(); ?>
<h2><?php the_title(); ?></h2>
...

But this way plugin developers or site authors require to edit print_breadcrumb() at functions.php to add their own breadcrumbs. Better way is using do_action()

...
<?php do_action('breadcrumb') ?>
<h2><?php the_title(); ?></h2>
...

Now you can add this in functions.php to get same behavior:

add_action('breadcrumb', 'print_breadcrumb'); 

Now a plugin author may override your code by:

add_action('breadcrumb', 'their_own_breadcrumb');

Not the answer you're looking for? Browse other questions tagged or ask your own question.