博客千篇一律的keywords和Description无论对搜索引擎还是用户,都不是一个很好的体验,所以有必要修改一下代码,在不同的页面显示相应的meta.

<?php
if(is_archive()){ 
  $category=get_the_category();
  $description=$category[0]->cat_name;
  $keywords = “”;       
  $tags =get_the_category($cat->ID);
  foreach($tags as $category) {
    $keywords=$category->category_description . ‘ ‘;
}

}
elseif(is_single()){ 
  $description =$post->post_title ;
  $keywords = “”;       
  $tags = wp_get_post_tags($post->ID);
  foreach ($tags as $tag ) {
    $keywords = $keywords . $tag->name . “, “;
  }
}
else{
  $description =get_bloginfo(name).’:致力于打造一个集UI设计/平面设计/网页设计/互动设计于一体的交流平台。’;
  $keywords =get_bloginfo(description);
}
if($keywords==”){
$keywords =get_bloginfo(description);
}
if($description==”){
  $description =get_bloginfo(name).’:致力于打造一个集UI设计/平面设计/网页设计/互动设计于一体的交流平台。’;
}
echo”<meta name=’Keywords’ content=’$keywords’ />”;
echo”<meta name=’Description’ content=’$description’ />”;
?>

注:请将代码部分的中文全角标点符号手动改为英文半角

做人要厚道,转载请注明文章来源: https://www.boxui.com/blog-history/277.html