Home >> 有关SEO > 给wordpress博客加上description标签

给wordpress博客加上description标签

今天,参考网络上的资料,给自己的这个wordpress博客加上了description标签。因为keywords标签对于SEO基本没有效果了,也就懒的加上了。

具体操作是在header.php里面的<head></head>之间(最好是紧跟在title标签后面)加上了下面一段代码:

<?php
if (is_home()){
$description = "Vaeky的个人博客,记录生活、工作、互联网上有趣的事情。";
} elseif (is_single() || is_page()){
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 = substr($post_content,0,220);
}
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag ) {
}
}
?>
<meta name="description" content="<?php echo trim($description); ?>" />

这段代码加上去以后,博客文章页面的description内容是选取博文的第一段。也就基本实现了每个页面的description不同。

  1. No Comments Yet