Display all hooks sequentialy that run on a page - WordPress
Debugging WordPress code is an interesting job. If the issue is too complicated, finding the cause is an awesome activity.
As a technical support in a development company, often I have to face such issue. Our clients always will come with some interesting bugs. Almost, the cause is not from our plugin or theme. But we have responsibility to find out the cause.
In such situations, getting an idea about all hooks that run on that WordPress page helped me a lot. Below you can find the function that I’m using for debugging.
add_action( 'all', 'th_show_all_hooks' );
function th_show_all_hooks( $tag ) {
if(!(is_admin())){ // Display Hooks in front end pages only
$debug_tags = array();
global $debug_tags;
if ( in_array( $tag, $debug_tags ) ) {
return;
}
echo "<pre>" . $tag . "</pre>";
$debug_tags[] = $tag;
}
}
You can use above code in your theme’s functions.php
file or in your custom plugin file. Now this code only display hooks in front end pages. To track hooks in backend, just update the conditional tag.
Note: This function only works in server with PHP 5.3+ versions and a global variable is used (It consider as bad practice).
Looking for a skilled WordPress/WooCommerce developer? I'm currently available for freelance, contract, or full-time remote opportunities! Let's create something amazing together. Send me a quick message, and I'll respond within 24 hours!
Recent Posts
- Automating Code Linting with GitHub Actions for WordPress Plugins
- Comprehensive Guide to Linting PHP, JavaScript, and CSS in WordPress Plugins Using Composer
- The Ultimate Guide to Indexing in Database Design
- Understanding 'update_meta_cache' in WordPress - When to Use It, When Not to, and Its Impact on Database Queries
- A Guide to Configuring JavaScript and SCSS Paths in WordPress Plugins with @wordpress/scripts
Your Questions / Comments
If you found this article interesting, found errors, or just want to discuss about it, please get in touch.