Count & Display Database Queries

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