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>);
然后我们刷新网页,它会没事的。那么如果我们想让一些地方不被压缩,我们应该怎么做呢?
我们可以遵循以下格式:
<span class="hljs-comment"><!--wp-compress-html--></span><span class="hljs-comment"><!--wp-compress-html no compression--></span>
不想压缩的地方
<span class="hljs-comment"><!--wp-compress-html no compression--></span><span class="hljs-comment"><!--wp-compress-html--></span>