List Every Hook Fired on a Page
Lets administrators add ?wpide_hooks=1 to any front-end URL to see, at the bottom of the page, every action and filter that ran and how many times, in firing order.
Opens WPIDE on
Code
if ( isset( $_GET['wpide_hooks'] ) ) {
$wpide_hook_counts = array();
add_action( 'all', function ( $hook ) use ( &$wpide_hook_counts ) {
$wpide_hook_counts[ $hook ] = ( $wpide_hook_counts[ $hook ] ?? 0 ) + 1;
} );
add_action( 'wp_footer', function () use ( &$wpide_hook_counts ) {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
echo '<details open style="margin:2rem;padding:1rem;background:#fff;color:#1d2327;border:1px solid #c3c4c7;font:13px/1.5 monospace;position:relative;z-index:99999">';
echo '<summary><strong>' . count( $wpide_hook_counts ) . ' hooks fired</strong></summary><ol style="columns:2;margin:1rem 0 0 1.5rem">';
foreach ( $wpide_hook_counts as $hook => $count ) {
echo '<li>' . esc_html( $hook ) . ( $count > 1 ? ' <em>×' . (int) $count . '</em>' : '' ) . '</li>';
}
echo '</ol></details>';
}, PHP_INT_MAX );
}
Notes
Tracking only starts when the parameter is present, so normal page loads are not slowed down.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.