第一步
编辑functions.php 添加函数
第二步
编辑header.php在<!DOCTYPE html>上面添加函数<?php define('START_TIME',runTime()); ?><!--开始计算-->
第三步
编辑footer.php在要显示的地方添加耗时:<?php echo round(runTime()-START_TIME,5); ?><!--计算结束显示-->这样就搞定了
第二种方法 推荐使用
- 在当前主题的functions.php文件添加下面的代码:
1function timer_start() {
2 global $timestart;
3 $mtime = explode( ' ', microtime() );
4 $timestart = $mtime[1] + $mtime[0];
5 return true;
6}
7timer_start();
8function timer_stop( $display = 0, $precision = 3 ) {
9 global $timestart, $timeend;
10 $mtime = explode( ' ', microtime() );
11 $timeend = $mtime[1] + $mtime[0];
12 $timetotal = number_format( $timeend - $timestart, $precision );
13 $r = $timetotal < 1 ? $timetotal * 1000 . " ms" : $timetotal . " s";
14 if ( $display ) {
15 echo $r;
16 }
17 return $r;
18}
- 在要显示加载时间的位置添加调用代码 一般都是
footed和post页面
1页面耗时:<?php echo timer_stop();?>
- 保存后,到前台刷新页面即可显示加载时间。