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地址:18.116.15.3,归属地:俄亥俄州Dublin ,欢迎您的访问!

温馨提示 : 非特殊注明,否则均为李联华的博客原创文章,本站文章未经授权禁止任何形式转载
文章链接:https://www.ooize.com/wordpress-compress-the-source-code-so-that-others-have-nowhere-to-steal.html
订阅
提醒
guest
0 评论
内联反馈
查看所有评论
Loading...