1. 404 重定向页面
<IfModule mod_alias.c> RedirectMatch 301 ^/search/$ http://your-site.com/ RedirectMatch 301 ^/tag/$ http://your-site.com/ RedirectMatch 301 ^/category/$ http://your-site.com/ </IfModule>
404 错误页面是这些页面产生当没有网页内容所指定的。坏的部分是,404 页,404 页减少你的博客的 Pagerank 使你的站点排名无效。所以, 我们将致力于改善 SEO 是利用 WordPress Hack 404 错误页面的重定向到博客的主页。
2. 自动从 URL 中删除停止词
add_filter('sanitize_title', 'remove_short_words');
function remove_short_words($slug) {
if (!is_admin()) return $slug;
$slug = explode('-', $slug);
foreach ($slug as $k => $word) {
if (strlen($word) < 3) {
unset($slug[$k]);
}
}
return implode('-', $slug);
}
当你写博客文章的标题在 WordPress, 根据标题永久链接调整你写的。人们认为我们不应该停止的话, 像对,, 等的博客文章的永久链接。它提高了搜索引擎优化, 还有助于期望从 URL 的内容只。所以, 为了使工作自动完成, 使用代码片段来自动删除 stop 单词从永久链接来提高 SEO 。
3. 突出关键字在搜寻结果
function wps_highlight_results($text){
if(is_search()){
$sr = get_query_var('s');
$keys = explode(" ",$sr);
$text = preg_replace('/('.implode('|', $keys) .')/iu', '<strong>'.$sr.'</strong>', $text);
}
return $text;
}
add_filter('the_excerpt', 'wps_highlight_results');
add_filter('the_title', 'wps_highlight_results');
使用此代码段突出显示搜索词在你的博客搜索结果 the_excerpt 和 the_title 。
4. 改写搜索结果的永久链接
function search_url_rewrite_rule() {
if ( is_search() && !empty($_GET['s'])) {
wp_redirect(home_url("/search/") . urlencode(get_query_var('s')));
exit();
}
}
add_action('template_redirect', 'search_url_rewrite_rule');
这个片段可以帮助你像 「yourblog.com/搜索/搜索关键字」 的搜索结果永久改写,最终其比默认搜索永久性的更好,从而提高搜索引擎优化。
5. 谷歌机器人的禁止目录
User-agent: Googlebot Allow: /?display=wide Disallow: /wp-content/ Disallow: /trackback/ Disallow: /wp-admin/ Disallow: /feed/ Disallow: /index.php Disallow: /*? Disallow: /*.js$ Disallow: /*.inc$ Disallow: /*.css$ Disallow: */feed/ Disallow: */trackback/ Disallow: /link.php Disallow: /gallery2 Disallow: /gallery2/ Disallow: /refer/ User-agent: Googlebot-Image Disallow: /wp-includes/ User-agent: Mediapartners-Google* Disallow:
使用这段代码片段在你的机器人,txt 文件来防止 Gogole 机器人能像 wp-content 指数不期望的目录,wp-includes 等等。