WordPress – Display Total Number of SQL Queries on Your Blog

Queries are evil. They slow down your site as you begin to accumulate more, which can negatively effect the user experience.
In fact, Google agrees too.

The first step to lowering queries is to know how many you actually have. Simply paste the following line of code somewhere on your site. I prefer going after the footer.php file.

<?php if (is_user_logged_in()) { ?>
    <?php echo get_num_queries(); ?> queries in <?php timer_stop(1); ?> seconds.
<?php } ?>

If you want this to be publicly shown, simply remove lines 1 and 3.

Leave a Reply

Your email address will not be published. Required fields are marked *