ad_728x90

參觀我的【 伊生活小舖】

2015年12月24日 星期四

強化wordpress文章seo

搜尋引擎除了逛我們的網站,也會讀取所有的頁面,更包含了文章。
尤其是文章內容的關鍵詞彙。
而可以不需要外掛的方式,就使用代碼完成,這樣可以加速網站速度。
將以下代碼放入主題的functions.php即可
============
//讓文章自動seo關鍵字與描述
function get_cats_name() {
$allcats=get_categories();
foreach ($allcats as $category)
{
$keywords[] = $category->cat_name;
}
return $keywords;
}
// utf8 substr
function utf8Substr($str, $from, $len) {
return preg_replace('#^(?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$from.'}'.
'((?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$len.'}).*#s',
'$1'
,$str);
}
// Meta SEO
function meta_SEO() {
global $post;
$output = '';
if (is_single()){//如果是文章頁
$keywords = '';
$description = '';
if ($post->post_excerpt) {//如果文章摘要存在就以文章摘要為描述
$description = $post->post_excerpt;
$description = str_replace("rn","",$description);
$description = str_replace("n","",$description);
$description = str_replace(""","'",$description);
$description .= '
...';
} else {//如果文章摘要不存在就截斷文章前200字為描述
$description = utf8Substr(strip_tags($post->post_content),0,200);
$description = str_replace("rn","",$description);
$description = str_replace("n","",$description);
$description = str_replace(""","'
",$description);
$description .= '...';
}
$tags = wp_get_post_tags($post->ID);//獲取文章標籤
foreach ($tags as $tag ) {
$keywordarray[] = $tag->name;
}
//以文章標籤為關鍵字
$keywords = implode(',',array_unique((array)$keywordarray));
} else {//如果不是文章頁
$keywords = '關鍵字,關鍵字,關鍵字,關鍵字,關鍵字,關鍵字,關鍵字,關鍵字,關鍵字,關鍵字,; //在引號間寫入你博客的關鍵字用,斷開
$description = '寫入網站描述,200字以內';//在這邊寫入你網站的簡單描述,不要過200字
}
//輸出關鍵字
$output .= '' . "
n";
$output .= '' . "
n";
//輸出描述
echo "
$outputn";
}
add_action('wp_head', 'meta_SEO');//增加meta_SEO函數到頭部資訊裡
add_filter( 'comment_text' , 'ludou_comment_add_at', 20, 2);



from:http://dhamma.com.tw/%E4%B8%8D%E7%94%A8%E5%A4%96%E6%8E%9B%EF%BC%8C%E5%BC%B7%E5%8C%96wordpress%E6%96%87%E7%AB%A0seo/

COMMENTS HAVE BEEN DISABLED FOR THIS POST [文章的評論已被禁用]

Ratings and Recommendations by outbrain