![图片[1]-WordPress显示查询次数、查询时间及消耗内存代码分享-轻刻年轮](https://www.ly522.com/wp-content/uploads/2018/08/1778-2-600x600.png)
其实这个功能是个可有可无的功能,如果非要折腾,加上这个也效果非常棒。
效果图
![图片[2]-WordPress显示查询次数、查询时间及消耗内存代码分享-轻刻年轮](https://www.ly522.com/wp-content/uploads/2018/08/1778.png)
主题 全局配置文件 中
在functions.php文件中加入以下代码:
有些主题会是在functions-theme.php文件中:
/*
让WordPress显示查询次数、查询时间及消耗内存
https://www.ly522.com
*/
function performance( $visible = true ) {
$stat = sprintf( '%d 次查询 | 用时 %.3f 秒 | 消耗 %.2fMB 内存',
get_num_queries(),
timer_stop( 0, 3 ),
memory_get_peak_usage() / 1024 / 1024
);
echo $visible ? $stat : "<!-- {$stat} -->" ;
}
如果调用的话可以用下面的代码进行(一般放在footer.php文件中):
本页面加载共:<?php if(function_exists('performance')) performance(true) ;?>
© 版权声明
THE END















![表情[qiang]-轻刻年轮](https://www.ly522.com/wp-content/themes/zibll/img/smilies/qiang.gif)
666
暂无评论内容