-1

In my wordpress project I have seen several times the use of do_action() function.

I don't know the working of this function, nor why we call it or where we use it?

Can someone please explain this to me?

1
  • Not to be rude or anything, but have you actually tried searching before you posted your question here. Have a look at my search results Commented May 29, 2014 at 7:34

2 Answers 2

1

Check out the WordPress Codex Krishan: do_action

I quote from that codex page

Execute functions hooked on a specific action hook.

This function invokes all functions attached to action hook $tag. It is possible to create new action hooks by simply calling this function, specifying the name of the new hook using the $tag parameter. You can pass extra arguments to the hooks, much like you can with apply_filters(). This function works similar to apply_filters() with the exception that nothing is returned and only the functions or methods are called.

You can hook a function to an action hook using add_action().

2
  • Well Pieter, what am I supposed to write? The same thing as the WordPress Codex? I don't think I could explain it better. I guess next time I'll just leave this kind of questions alone.
    – Ricard
    Commented May 29, 2014 at 7:32
  • 1
    What you could write is an answer based on your own personal authentic experience as this is unique. A solution you also test is better than one you don't. Commented May 29, 2014 at 10:55
1

There's different uses for the do_action hook in WordPress.

One way to use do_action is for creating new hooks which i have already written about.

https://wordpress.stackexchange.com/a/144883/9884

  1. This enables you to add a custom hook in your parent themes template.

  2. You can then use the custom hook in an add_action function in your child theme to hook in new content, a widget or a template tag for a slider as one example.

You can also add a conditional tag after the function for more control over which pages your function executes.

The custom hook can be used many times so you don't need to keep modifying your parent themes files.

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