Last active
November 13, 2017 12:23
-
-
Save andandehei/94cf03259797a88a5fdd to your computer and use it in GitHub Desktop.
wordpress加速:纯代码方法压缩wordpress网页代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
*压缩html代码 | |
*/ | |
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("\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]; | |
} | |
return $buffer_out; | |
} | |
ob_start("wp_compress_html_main"); | |
} | |
add_action('get_header', 'wp_compress_html'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment