Skip to content

WordPress hooks debugging — finding which action or filter actually fired

A WordPress hook is misbehaving and you can't tell which plugin attached the callback. The tools and techniques to surface which actions and filters fired, in what order, and from where.

A WordPress page renders with a strange message in the header that nobody on the team added. Search the theme — nothing. Search active plugins — nothing. It’s coming from a callback attached to wp_head, but which one? WordPress doesn’t tell you. The hook system is the wiring of WordPress, and debugging it means knowing what fired, in what order, and from where.

What’s happening

WordPress runs on actions and filters. Plugins and themes register callbacks with add_action() and add_filter(). At runtime, do_action() and apply_filters() invoke every registered callback in priority order. The same hook can have callbacks from core, from your theme, and from a dozen plugins. WordPress provides no built-in introspection — you can call has_action('wp_head'), but the return is true or a priority number, not “Yoast SEO at priority 5 attached the og:title line.”

The trace surface is the global $wp_filter array. Each hook name is a key, with WP_Hook objects as values describing every registered callback. Dumping $wp_filter['wp_head'] shows the full attachment list. That’s the building block for every debugging technique below.

How to verify

For any suspect hook, dump the full callback list with WP-CLI:

wp eval '
$hook = "wp_head";
global $wp_filter;
if (!isset($wp_filter[$hook])) { echo "No callbacks on $hook"; return; }
foreach ($wp_filter[$hook] as $priority => $callbacks) {
  foreach ($callbacks as $cb) {
    $fn = $cb["function"];
    if (is_array($fn)) {
      $class = is_object($fn[0]) ? get_class($fn[0]) : $fn[0];
      $fn = "$class::$fn[1]";
    } elseif ($fn instanceof Closure) {
      $r = new ReflectionFunction($fn);
      $fn = $r->getFileName() . ":" . $r->getStartLine();
    }
    echo "[$priority] $fn\n";
  }
}
'

Output lists every callback, its priority, and either the class+method or the file:line for closures — the latter is what finds anonymous functions hiding in functions.php.

For runtime tracing (which hook fires when), Query Monitor surfaces the full hook flow in its Hooks & Actions panel. Install it on staging:

wp plugin install query-monitor --activate

Load the page in question, then click the Query Monitor menu bar item. Hooks & Actions lists every fired hook with the file:line of each callback.

What to do

The debugging flow, from “something fires” to “this plugin attached the callback.”

  1. Identify the hook. If a string is in the output (“Welcome back!”), grep -rn "Welcome back" wp-content/ finds the source file most of the time. If the string is dynamic, work backwards from where in the HTML it appears (</head> means wp_head, <footer> means wp_footer).

  2. Dump the hook’s callbacks with the WP-CLI snippet above. Read the file:line for each attachment. One of them is responsible.

  3. Disable callbacks one at a time to confirm. The cleanest way is to temporarily attach a higher-priority callback that removes the suspect:

add_action('wp_head', function() {
    // tell us what's there at priority 0
    global $wp_filter;
    error_log(print_r($wp_filter['wp_head'], true));
    // then remove the suspect
    remove_action('wp_head', ['Suspect_Plugin_Class', 'output_meta'], 5);
}, 0);
  1. For closures and dynamic attachment, use Xdebug or a debug_backtrace() call inside the hook. Drop a temporary mu-plugin that traces the hook:
<?php
// wp-content/mu-plugins/trace-hook.php
add_action('wp_head', function() {
    error_log(wp_debug_backtrace_summary(null, 0, false) . "\n");
}, 999);
  1. For order-of-execution issues (the wrong plugin runs first), check priorities. add_action('init', 'callback', 5) runs before priority 10. If two plugins register at the same priority, the order they registered in matters — that’s almost always the wp-content/plugins/ directory order, which is alphabetical.

  2. For “the hook isn’t firing at all”, confirm the hook name and timing:

wp eval 'echo did_action("wp_head") . "\n";'   # how many times fired
wp eval 'echo (current_action() ?: "no action active") . "\n";'

If did_action() returns 0, the hook hasn’t fired in the current request — wrong page template, wrong context, or the hook itself was removed.

  1. For frontend-only issues, browser DevTools network tab + Query Monitor on the rendered page is the fastest path. Server-side issues (REST endpoints, cron callbacks) want the CLI trace approach above.

For the surrounding development workflow that prevents these surprises, Stack Harbor’s enterprise WordPress hosting practice instruments hook usage as part of every onboarding. If a site has surprises in wp_head that nobody owns, we can do the audit.