WordPress的Description、Keywords优化

依次找到 wp-content/themes/你的主题名称/  下的header.php文件

然后在 <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" /> 这段的后面,添加下面的代
<?php
if (!function_exists('utf8Substr')) {
 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);
 }
}
 if (is_home()){
    $description = "你的WordPress的描述";
    $keywords = "关键字1,关键字2";
} elseif (is_single()){
    if ($post->post_excerpt) {
        $description  = $post->post_excerpt;
    } else {
   if(preg_match('/<p>(.*)<\/p>/iU',trim(strip_tags($post->post_content,"<p>")),$result)){
    $post_content = $result['1'];
   } else {
    $post_content_r = explode("\n",trim(strip_tags($post->post_content)));
    $post_content = $post_content_r['0'];
   }
         $description = utf8Substr($post_content,0,220);  
  }
    $keywords = "";     
    $tags = wp_get_post_tags($post->ID);
    foreach ($tags as $tag ) {
        $keywords = $keywords . $tag->name . ",";
    }
}
?>
<meta name="description" content="<?php echo trim($description); ?>" />
<meta name="keywords" content="<?php echo rtrim($keywords,','); ?>" />

Pop提示:WordPress在IE下查看源文件为乱码的解决办法
http://429006.com/article/technology/2114.htm

原文地址:
http://liucheng.name/1127/
http://domety.com/archives/206/

Related Posts