给typecho博客添加网站加载时间
•建站折腾
4194 5
想及时了解自己的typecho博客访问速度,简单的代码就可以实现!
在typecho博客主题文件
functions.php 中加入以下代码:
/**
* 加载时间
* @return bool
*/
function timer_start() {
global $timestart;
$mtime = explode( ' ', microtime() );
$timestart = $mtime[1] + $mtime[0];
return true;
}
timer_start();
function timer_stop( $display = 0, $precision = 3 ) {
global $timestart, $timeend;
$mtime = explode( ' ', microtime() );
$timeend = $mtime[1] + $mtime[0];
$timetotal = number_format( $timeend - $timestart, $precision );
$r = $timetotal < 1 ? $timetotal * 1000 . " ms" : $timetotal . " s";
if ( $display ) {
echo $r;
}
return $r;
}
然后在你需要显示时间的地方调用即可,一般在网站底部footer.php中引用:
<?php echo timer_stop();?>
就是这么简单,快点去自己的 typecho博客出实践吧!
<?php echo timer_stop();?
这里少了一个>,我说呢→_→
已拿走,谢谢博主 ::twemoji:tongue::
来串串门
来逛逛 ::twemoji:tiaomei:: 嘿嘿 ::twemoji:cool::
不错 ::twemoji:smile::