How do I display database query statistics on Wordpress site?

I've noticed that a few Wordpress blogs have query statistics present in their footer that simply state the number of queries and the total time required to process them for the particular page, reading something like: 23 queries. 0.448 seconds.
I was wondering how this is accomplished. Is it through the use of a particular Wordpress plug-in or perhaps from using some particular php function in the page's code?
3 Answers
Try adding this to the bottom of the footer in your template:
<?php echo $wpdb->num_queries; ?> <?php _e('queries'); ?>. <?php timer_stop(1); ?> <?php _e('seconds'); ?>
* or wp-admin/admin-footer.php if you want it to show in the backend admin panel.
To explain pix0r's code:
$wpdb->num_queriesis the number of database queries._eis for localizationtimer_stop()returns the amount of time taken to render the page
wordpress has a easy solution now
There is a function called {get_num_queries()} and as specified in other answers {timer_stop()}.
<?php echo get_num_queries(); _e(' queries'); ?> in <?php timer_stop(1); _e(' seconds'); ?>
get_num_queries() - returns the number of database queries during the WordPress execution and accepts no parameters
Is there a way to put this in the backend admin panel too?
get_num_queries() function is a global function. The above snippet should work in backend admin panel (wp-admin area).
Thanks. The best place for this is at the end of wp-admin/admin-footer.php
WordPress 5.6 Beta 1 | Improvements in the Editor and Core
WordPress 5.6 Beta 1 is now available for testing! This software is still in development, so we recommend that you run this version on a test site. You can test the WordPress 5.6 beta in two ways: Try the WordPress Beta Tester plugin (choose the “bleeding edge nightlies” option). Or download the beta (zip). The current target for final release is December 8, 2020. This is just seven weeks away, so your help is needed to ensure this release is tested properly. Improvements in the Editor WordPress 5.6 includes seven Gutenberg plugin releases. Here are a few highlighted enhancements: Improved support for video positioning in cover blocks. Enhancements to Block Patterns including translatable strings. Character counts in the information panel, improved keyboard navigation, and other adjustments to help users find their way better. Improved UI for drag and drop functionality, as well as block movers. To see all of the features for each…
Visual Studio Code September 2020 (version 1.50) (part 3)
Editor Trigger IntelliSense For years, Ctrl+Space has been the predominant keybinding to trigger IntelliSense. However, on macOS and Windows, the same keybinding is used to toggle between keyboard layouts. To minimize confusion, we added another keybinding to trigger IntelliSense: on Windows and Linux it's Ctrl+I , and on macOS it's Cmd+I . Debugging Debug hover improvements Language hover now available while debugging While debugging, the debug hover takes precedence over the language hover, making it impossible to see the language hover. Starting with this release, you can switch from the debug hover back to the language hover by holding…
Visual Studio Code September 2020 (version 1.50) (part 2)
Workbench Pinned tabs improvements Pinned tabs were introduced in our May 2020 release. Since then, we've received valuable feedback on how to improve this experience further, and for this milestone there are a couple of changes worth mentioning. A new setting workbench.editor.pinnedTabSizing allows you to configure how large a pinned tab should appear: normal : a pinned tab inherits the look of other tabs (new default) shrink : a pinned tab…


