
wordpress网站如何不利用插件压缩前端html代码,下面web建站小编给大家详细介绍一下具体实现代码!
在当前主题的functions.php文件中新增以下代码:
function wp_compress_html() {
function wp_compress_html_main ($buffer) {
$initial=strlen($buffer);
$buffer=explode("<!--wp-compress-html-->", $buffer);
$count=count ($buffer);
for ($i = 0; $i <= $count; $i++) {
if (stristr($buffer[$i], '<!--wp-compress-html no compression-->')) {
$buffer[$i]=(str_replace("<!--wp-compress-html no compression-->", " ", $buffer[$i]));
} else {
$buffer[$i]=(str_replace("t", " ", $buffer[$i]));
$buffer[$i]=(str_replace("nn", "n", $buffer[$i]));
$buffer[$i]=(str_replace("n", "", $buffer[$i]));
$buffer[$i]=(str_replace("r", "", $buffer[$i]));
while (stristr($buffer[$i], ' ')) {
$buffer[$i]=(str_replace(" ", " ", $buffer[$i]));
}
}
$buffer_out.=$buffer[$i];
}
return $buffer_out;
}
ob_start("wp_compress_html_main");
}
add_action('get_header', 'wp_compress_html');
标签: wordpress压缩代码, wordpress建站, wordpress技巧
上面是“wordpress网站如何压缩前端html代码(非插件)”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_3777.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

Google PR是什么意思?到底有什么作用呢?
企业微信网页版官方登录入口,无需下载客户端直接网上办公
星空外语
中国军事百科全书数据库:包含约3万个条目、3600万字的文字内容、2万余幅图片和表格