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末尾即可

温馨提示 : 非特殊注明,否则均为©李联华的博客网原创文章,本站文章未经授权禁止任何形式转载;IP地址:3.140.196.5,归属地:俄亥俄州Dublin ,欢迎您的访问!
文章链接:https://www.lilianhua.com/wordpress-compress-the-source-code-so-that-others-have-nowhere-to-steal.html
Popup Image

通知

本站原则上是免费提供技术支持,但是服务器维护和运营成本高,可以实行自由赞助:赞助

Loading...