女武神的终末第三季免费观看,国产精品va无码二区,欧美日韩在线视频观看,国产在线观看网站

代碼實現WordPress自動關鍵詞keywords與描述description

2015-08-03 wordpress教程
  • 文章介紹
  • 快速入門
  • 評價&建議

以下代碼實現的是以標簽為關鍵詞;以摘要為描述,如果沒有填寫摘要,那就自動截取文章前200字為描述。(教程轉自:DeveWork)

代碼實現WordPress自動關鍵詞與描述:

以下代碼放到你的主題下funtions.php的最后一個 ?>前:

  1. //自動關鍵詞與描述?
  2. function?get_cats_name()?{
  3. $allcats=get_categories();
  4. foreach?($allcats?as?$category)
  5. {
  6. $keywords[]?=?$category->cat_name;
  7. }
  8. return?$keywords;
  9. }
  10. //?utf8?substr
  11. function?utf8Substr($str,?$from,?$len)?{
  12. return?preg_replace('#^(?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$from.'}'.
  13. '((?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$len.'}).*#s',
  14. '$1',$str);
  15. }
  16. //?Meta?SEO
  17. function?meta_SEO()?{
  18. global?$post;
  19. $output?=?'';
  20. if?(is_single()){//如果是文章頁
  21. $keywords?=?'';
  22. $description?=?'';
  23. if?($post->post_excerpt)?{//如果文章摘要存在就以文章摘要為描述
  24. $description?=?$post->post_excerpt;
  25. $description?=?str_replace("rn","",$description);
  26. $description?=?str_replace("n","",$description);
  27. $description?=?str_replace(""","'",$description);
  28. $description?.=?'...';
  29. }?else?{//如果文章摘要不存在就截斷文章前200字為描述
  30. $description?=?utf8Substr(strip_tags($post->post_content),0,200);
  31. $description?=?str_replace("rn","",$description);
  32. $description?=?str_replace("n","",$description);
  33. $description?=?str_replace(""","'",$description);
  34. $description?.=?'...';
  35. }
  36. $tags?=?wp_get_post_tags($post->ID);//取文章標簽
  37. foreach?($tags?as?$tag?)?{
  38. $keywordarray[]?=?$tag->name;
  39. }
  40. //以文章標簽為關鍵字
  41. $keywords?=?implode(',',array_unique((array)$keywordarray));
  42. }?else?{//如果不是文章頁
  43. $keywords?=?'wordpress,wordpress主題,wordpress教程,wordpress主題下載,wordpress博客主題,wordpress企業主題,wordpress主題定制';?//在引號間寫入你博客的關鍵字用,斷開
  44. $description?=?'主題貓,致力于為廣大網友提供最新最全的wordpress主題';//在引號間寫入你博客的簡單描述,不要過200字
  45. }
  46. //輸出關鍵字
  47. $output?.=?'<meta?name="keywords"?content="'?.?$keywords?.?'"?/>'?.?"n";
  48. $output?.=?'<meta?name="description"?content="'?.?$description?.?'"?/>'?.?"n";
  49. //輸出描述
  50. echo?"$outputn";
  51. }
  52. add_action('wp_head',?'meta_SEO');//添加meta_SEO函數到頭部信息里

第43行與第44行的內容需要根據你的網站進行修改。

1 0

企業建站推薦正版商業主題,國內專業團隊開發,完善售后,是您不二選擇。

正版主題商店

主題貓WP建站,累計幫助1300+客戶成功建站,為站長提供支持!

立刻開啟你的建站之旅
QQ在線客服

服務熱線

wordpress建站咨詢