不使用插件哦,直接放进函数内即可!functions.php 内
/* *压缩html代码 * http://www.WordPress.com */ function wp_compress_html() {
function wp_compress_html_main ($buffer) { $initial=strlen($buffer); $buffer=explode("", $buffer); $count=count ($buffer);
for ($i = 0; $i <= $count; $i++) { if (stristr($buffer[$i], ' ')) { $buffer[$i]=(str_replace(" ", " ", $buffer[$i])); } else { $buffer[$i]=(str_replace("\t", " ", $buffer[$i])); $buffer[$i]=(str_replace("\n\n", "\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]; } //$final=strlen($buffer_out); //$savings=($initial-$final)/$initial*100; //$savings=round($savings, 2); //$buffer_out.="\n"; return $buffer_out; }
ob_start("wp_compress_html_main"); }
add_action('get_header', 'wp_compress_html');
嗯,这回绝对简单,放到文件?>前面即可,注意要是半角哦,否则网站打不开,概不负责!
最好不要使用记事本进行编辑,编辑前请备份! 出错后,网站将无法打开!
713146 364003Top rated lad speeches and toasts, as nicely toasts. may possibly extremely nicely be supplied taken into consideration producing at the party consequently required to be just a little a lot more cheeky, humorous with instructive on top of this. finest man speeches funny 766369
2018年8月14日 17:25用了之后首页显示空白,不能加载怎么办
2016年1月9日 22:16全白还是?
2016年1月23日 16:34亲!全部都复制进去了,怎么不能用呢?
2015年6月2日 18:58放进function.php里?
2015年6月2日 19:20227185091 加群给源码
2015年6月2日 19:21我太贱了不错的样子呀~
2015年3月1日 18:59现在都用的七牛或者又拍了,没有必要压缩了吧?
2015年1月26日 20:55站点总不能也用吧
2015年1月27日 12:37站点总不能也用吧
2015年1月27日 12:37纳尼?怎么不直接一个代码框?
2015年1月25日 21:53好吧-_-||才发现
2015年1月26日 00:57学习了
2015年1月3日 14:30原来是将 html 提前加载了,是个好的功能。
2014年12月26日 09:58这个可以有,如果流量大了必须的各种优化
2014年12月25日 21:07