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地址:44.222.82.133,归属地:弗吉尼亚州Ashburn ,欢迎您的访问!
文章链接:https://www.ooize.com/wordpress-compress-the-source-code-so-that-others-have-nowhere-to-steal.html
文章链接:https://www.ooize.com/wordpress-compress-the-source-code-so-that-others-have-nowhere-to-steal.html
订阅
登录
0 评论