免费领流量卡 | 广告招租 |
WordPress的SEO优化不仅仅是为了优化百度关键词排名,简单的说,如果你的网站很轻便,浏览速度很快,那你的网站访问量就很可观,也就是说用户体验良好,那就需要进行WordPress各方面的优化。
主题 全局配置文件 中,在 functions.php
文件中加入以下代码:
有些主题会是在functions-theme.php文件中:
<span class="hljs-comment">/*
WordPress免插件网页代码压缩
*/</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">wp_compress_html</span><span class="hljs-params">()</span></span>{
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">wp_compress_html_main</span> <span class="hljs-params">($buffer)</span></span>{
$initial=strlen($buffer);
$buffer=explode(<span class="hljs-string">"<!--wp-compress-html-->"</span>, $buffer);
$count=count ($buffer);
<span class="hljs-keyword">for</span> ($i = <span class="hljs-number">0</span>; $i <= $count; $i++){
<span class="hljs-keyword">if</span> (stristr($buffer[$i], <span class="hljs-string">'<!--wp-compress-html no compression-->'</span>)) {
$buffer[$i]=(str_replace(<span class="hljs-string">"<!--wp-compress-html no compression-->"</span>, <span class="hljs-string">" "</span>, $buffer[$i]));
} <span class="hljs-keyword">else</span> {
$buffer[$i]=(str_replace(<span class="hljs-string">"\t"</span>, <span class="hljs-string">" "</span>, $buffer[$i]));
$buffer[$i]=(str_replace(<span class="hljs-string">"\n\n"</span>, <span class="hljs-string">"\n"</span>, $buffer[$i]));
$buffer[$i]=(str_replace(<span class="hljs-string">"\n"</span>, <span class="hljs-string">""</span>, $buffer[$i]));
$buffer[$i]=(str_replace(<span class="hljs-string">"\r"</span>, <span class="hljs-string">""</span>, $buffer[$i]));
<span class="hljs-keyword">while</span> (stristr($buffer[$i], <span class="hljs-string">' '</span>)) {
$buffer[$i]=(str_replace(<span class="hljs-string">" "</span>, <span class="hljs-string">" "</span>, $buffer[$i]));
}
}
$buffer_out.=$buffer[$i];
}
$final=strlen($buffer_out);
$savings=($initial-$final)/$initial*<span class="hljs-number">100</span>;
$savings=round($savings, <span class="hljs-number">2</span>);
<span class="hljs-keyword">return</span> $buffer_out;
}
ob_start(<span class="hljs-string">"wp_compress_html_main"</span>);
}
add_action(<span class="hljs-string">'get_header'</span>, <span class="hljs-string">'wp_compress_html'</span>);
然后我们刷新网页就OK了。那么如果我们要一些地方不要压缩,该如何做呢?
我们可以按照这个格式:
<span class="hljs-comment"><!--wp-compress-html--></span><span class="hljs-comment"><!--wp-compress-html no compression--></span>
不想压缩的地方
© 版权声明
免责声明:本站采用CC BY-NC-SA 4.0协议,完整转载请注明来自狐狸资源网
THE END
暂无评论内容