WordPress 显示网站加载时间

Gavin Wu 2022年10月21日 14:10 Wordpress 567 Views

在 functions.php中添加以下代码

1
2
3
4
5
6
7
//显示页面查询次数、加载时间和内存占用
function performance( $visible = false ) {
    $stat = sprintf(  '本次加载耗时:%.3fs',
        timer_stop( 0, 3 )
    );
    echo $visible ? $stat : "<!-- {$stat} -->" ;
}

在需要调用的位置添加以下代码:

1
<?php if(function_exists('performance')) performance(true) ;?>

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Top