前言
今天有个群友要在网站底部添加页面生成时间和数据库查询次数,虽然wpopt插件可以实现这个功能,但是仅能管理员查看
效果图![图片[1]-WordPress底部添加页面生成时间和数据库查询次数-爱分享-探索世界](https://likei.oss-cn-shanghai.aliyuncs.com/wp-content/uploads/2024/12/12cb62bd07ff892ee7f0d29bbc84a463.webp)
教程
1.首先在function.php 文件中添加如下代码,有子主题可以添加到子主题中
function display_query_count_with_timer() {
$query_count = get_num_queries();
$query_time = timer_stop(0, 3);
$output = "<p>本次数据库查询" . $query_count . "次,页面生成花费".$query_time."秒</p>";
return $output;
}
add_shortcode('query_timer', 'display_query_count_with_timer');
2.如果想添加在底部可以使用WordPress的小工具中的文本,只需要输入[query_timer] 即可。
© 版权声明
THE END









暂无评论内容