wordpress 压缩源代码,让别人无处可盗

//压缩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 ];
}
$final = strlen ( $buffer_out ); 
$savings =( $initial - $final )/ $initial *100; 
$savings = round ( $savings , 2); 

return $buffer_out ;
}
ob_start( "wp_compress_html_main" );
}
add_action( 'get_header' , 'wp_compress_html' );

将以上代码放入站点的functions.php末尾即可

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容