Skip to content

Instantly share code, notes, and snippets.

@andandehei
Last active November 13, 2017 12:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andandehei/94cf03259797a88a5fdd to your computer and use it in GitHub Desktop.
Save andandehei/94cf03259797a88a5fdd to your computer and use it in GitHub Desktop.
wordpress加速:纯代码方法压缩wordpress网页代码
<?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