wordpress 压缩源代码,让别人无处可盗
由
Deepseek提供支持
广告
//压缩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末尾即可
温馨提示 : 非特殊注明,否则均为©李联华的博客网原创文章,本站文章未经授权禁止任何形式转载;来自:俄亥俄州·哥伦布 ,欢迎您的访问!
文章链接:https://www.lilianhua.com/wordpress-compress-the-source-code-so-that-others-have-nowhere-to-steal.html
文章链接:https://www.lilianhua.com/wordpress-compress-the-source-code-so-that-others-have-nowhere-to-steal.html
English (US)
Español (ES)
Português (PT)
Français (CA)
Español (MX)
Español (VE)
Español (CO)
Español (AR)
Português (BR)
Quechua (PE)
Guaraní (PY)
简体中文 (ZH)
繁體中文 (HK)
日本語 (JP)
한국어 (KR)
हिन्दी (HI)
Pilipino (PH)
ไทย (TH)
Tiếng Việt (VN)
Bahasa Melayu (MY)
Bahasa Indonesia (ID)
বাংলা (BD)
اردو (PK)
සිංහල (LK)
ភាសាខ្មែរ (KH)
English (UK)
Français (FR)
Deutsch (DE)
Italiano (IT)
Русский (RU)
Nederlands (NL)
Türkçe (TR)
Polski (PL)
Svenska (SE)
Norsk (NO)
Dansk (DK)
Suomi (FI)
Ελληνικά (GR)
Čeština (CZ)
Magyar (HU)
Română (RO)
Български (BG)
Српски (RS)
Українська (UA)
