wordpress 主题 header 优化方案改进版

针对wordpress主题的SEO优化方案,在网上流传的方案基础上进行了改进——

以下代码替代header.php文件相应代码:

  1. <title>
  2. <?php
  3. if (is_single() || is_page() || is_archive()) { wp_title(,true) ; echo | ; }
  4. bloginfo(name);
  5. ?>
  6. </title>
  7.  
  8. <?php
  9. //以下优化搜索引擎对导航页重复内容收录问题:
  10. if (is_single() || is_page() || is_home() ) 
  11.     { echo <meta name="robots" content="index,follow" />; }
  12. else
  13.     { echo <meta name="robots" content="noindex,follow" />; }
  14. //针对baidu对index不准确识别的问题则改用以下代码:
  15. //if ( !(is_home()) and !(is_single()) ) { echo ‘<meta name="Googlebot" content="noindex,follow" />’; }
  16.  
  17. //以下优化description和keywords:
  18. if (is_single()) {
  19.     if ($post->post_excerpt) {
  20.         $description = $post->post_excerpt;
  21.     } else {
  22.         $description = substr(strip_tags($post->post_content),0,220);
  23.     }
  24.     $tags = wp_get_post_tags($post->ID);
  25.     foreach ($tags as $tag ) {
  26.         $keywords = $keywords . $tag->name . ", ";
  27.     }
  28. } elseif(is_category()) {
  29.     $description = category_description();
  30. }
  31.  
  32. if ($keywords) {
  33.     echo <meta name="keywords" content=" . $keywords . " />;
  34. }
  35. if ($description) {
  36.     echo <meta name="description" content=" . $description . " />;
  37. } else {
  38.     echo <meta name="description" content=";
  39.     bloginfo(description);
  40.     echo " />;
  41. }
  42. ?>

相关文章

Tags: , , ,

2 Responses to “wordpress 主题 header 优化方案改进版”

  1. 星际争霸2资料站 Says:

    不错不错

  2. 天龙八部资料站 Says:

    顶~~~~我叫天龙八部资料站,希望能交个朋友哈!

Leave a Reply