MENU
// //

Typecho添加页面加载时间

April 10, 2020 • typecho

在主题的funcation.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文件需要放置加载时间的地方添加(此主题在文件夹component下)

Site load time is:<?php echo timer_stop();?>
Last Modified: September 11, 2023