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 等等。