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;
}

然后在要显示的地方(一般是在网站底部主题foot.php文件)调用即可:

网页加载耗时:<?php echo timer_stop();?>

 

文章名:《Typecho添加网站加载时间
文章地址:https://for.886a.top/archives/277.html
来源:for.886a.top 星空社区
本站各类资源均来自互联网,仅供个人学习交流,请于下载后 24 小时内删除,不允许用于商业用途,否则自行承担法律问题。
THE END
分享
二维码
打赏
< <上一篇
下一篇>>
文章目录
关闭
目 录