Is there a way to check if a custom hook gets called upon? I would like to display a placeholder if no output will be passed to it.
2 Answers
I believe you are looking for has_action
, which should ...
Check if any action has been registered for a hook.
if (has_action('custom_action')) {
// stuff
} else {
// different stuff
}
-
Hm, okay, so this is what the question really was about... ;)– tfrommenCommented Feb 19, 2014 at 19:06
Do you know did_action
?
If I understood you correctly, you are looking for something like the following:
if (0 === did_action('custom_action')) {
// placeholder, or whatever
}
-
1Although did_action() is very useful too it works a little differently than what I was looking for in the end. If I'm correct did_action() counts the amount of time a specific do_action($) has been executed on different locations right?– user17235Commented Feb 19, 2014 at 19:38
-
Yes, that's right. And that's how I understood your question. Determine if a specific action has been called (until now) and react on that data.
has_action()
returnstrue
if there is at least one action registered - but it doesn't care if it's already been called or not.– tfrommenCommented Feb 19, 2014 at 19:49