Count & Display Database Queries

I’m looking for an solution how I can count and display all queries in a WordPress site.
Does anybody know, if there is an good plugin?

Otherwise it would be an solution to check the queries on the console, because I’m working a lot with the console.

2 s
2

You can paste this block of code in your currently active WordPress theme functions.php file:

function wpse_footer_db_queries(){
    echo '<!-- '.get_num_queries().' queries in '.timer_stop(0).' seconds. -->'.PHP_EOL;
}
add_action('wp_footer', 'wpse_footer_db_queries');

The above block of code, will render an HTML comment in the footer of your theme (before </body> and </html>, containing the number of database queries and how log they took to retrieve.

Leave a Comment