Many blogs display a 'page load time' notice, and it's a common request in WordPress communities. This tutorial explains how to add this feature to your site.
Preview
A text notice like "Page loaded in: 0.123 seconds" appears at the bottom or in the sidebar.
Basic Implementation
Place the following code where you want the load time to appear (e.g., in your theme's footer.php file). Refresh your site to see the result.
Page loaded in: <?php timer_stop(1); ?> seconds
Code Explanation
This uses WordPress's built-in timer_stop() function. The parameter 1 sets the decimal precision to one digit. Change it to 3 for three decimal places, etc.
Advanced: Create a Shortcode
To use the load time within posts or widgets via a shortcode, add this to your theme's functions.php:
function display_page_load_time() {
return 'Page loaded in: ' . timer_stop(0, 5) . ' seconds';
}
add_shortcode('load_time', 'display_page_load_time');
After adding, use the shortcode [load_time] in any post or text widget. In timer_stop(0, 5), the second parameter 5 sets the precision to five decimal places.
Important Notes
- Place code inside
<?php ... ?>tags in PHP template files. - Always use a child theme or backup files before editing theme files.
- The displayed time measures server-side page generation, not total browser load time (which includes network transfer and rendering).