REST API & Developer PHP Beginner

Display Query Count and Load Time in the Footer

Show the number of database queries and total page load time in the front-end footer for administrators, giving instant performance feedback during development.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 20 lines
add_action( 'wp_footer', function() {
    if ( ! current_user_can( 'manage_options' ) ) return;

    $queries   = get_num_queries();
    $load_time = timer_stop( 0, 3 );
    $memory    = round( memory_get_peak_usage() / 1024 / 1024, 2 );

    printf(
        '<div style="position:fixed;bottom:0;left:0;right:0;background:#0f172a;color:#94a3b8;'
        . 'font-family:monospace;font-size:12px;padding:6px 16px;z-index:99999;'
        . 'display:flex;gap:24px;border-top:1px solid #1e293b">'
        . '<span>📊 <strong style="color:#f1f5f9">%d</strong> queries</span>'
        . '<span>⏱ <strong style="color:#f1f5f9">%ss</strong> load</span>'
        . '<span>💾 <strong style="color:#f1f5f9">%sMB</strong> memory</span>'
        . '</div>',
        $queries,
        $load_time,
        $memory
    );
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

During development and performance work, the three numbers that matter most are database query count, page load time, and peak memory usage. Query Monitor provides all of this and much more, but it’s a full plugin with its own overhead. This snippet gives you the three essential metrics as a minimal, always-visible footer bar, no plugin needed, visible only to administrators, and removed entirely for regular visitors.

What the code does

The bar renders as a fixed-position element at the bottom of the viewport, styled with a dark background that contrasts clearly against most site designs.

The Three Metrics

get_num_queries() returns the total number of database queries executed during the current request, including all queries run by WordPress core, your theme, and every active plugin. High query counts are a common source of slow page loads, anything above 30–40 queries on a simple page warrants investigation.

timer_stop( 0, 3 ) returns the elapsed time since WordPress started loading, formatted to three decimal places in seconds. This is wall-clock time from the moment the WordPress bootstrap began to the moment the footer renders, it doesn’t include the browser’s network latency or rendering time, but it’s the server-side component of your Time to First Byte.

memory_get_peak_usage() returns the highest memory consumption reached at any point during the request in bytes. Dividing by 1024 twice converts it to megabytes. Comparing this against your PHP memory_limit setting tells you how much headroom you have before hitting the limit.

What Normal Looks Like

On a well-optimised WordPress site, typical ranges are: 15–25 database queries for simple pages, 50–100ms server load time, and 20–40MB peak memory. Pages with WooCommerce, complex menus, or many active plugins may run higher. Use these numbers as a baseline and watch for significant increases when activating new plugins or deploying code changes.

Remove in Production

Because the check is gated behind current_user_can( 'manage_options' ), non-admin visitors never see the bar and it never adds rendering overhead to their experience. You can leave this snippet active permanently as a development aid, or remove it before handing off a site to a client to keep the admin bar uncluttered.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only