How to check if an action is already fired in a function for example:

function foo() {
  // checking if the action 'wp' is fired
  if( !action_fired('wp') ) {
    trigger_error('invalid call');

  if( is_front_page() ) {
    // Do something

I want to check that because:

  1. WordPress conditional tags like is_front_page won't work being called before the 'wp' hook.

  2. Still, these conditional tags can be called before 'wp' without any warning or notices

So writing a function like foo(), I want to ensure it is called properly by throwing an error if the 'wp' action hasn't fired at that time.


How to check if an action is already fired?

The did_action( $tag) function returns the number of times the $tag action hook has fired.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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