WordPress SEO简单优化- 加入Keywords和description到meta中

WordPress 在撰写日志的时候,可以给日志添加摘要(excerpt)和标签(tag),我的做法就是,就如给日志添加了摘要就把摘要做为 Description,如果没有设置摘要的话,则截取文章的前 220 个字作为 Description,而标签直接作为 Keywords。代码如下:

<?php
if (is_home()){
$description = "neoReMinD.net是一个IT技术从业者的博客。";
$keywords = "neo remind blog software development test technology java ibm";
} elseif (is_single()){
if ($post->post_excerpt) {
$description  = $post->post_excerpt;
} else {
$description = substr(strip_tags($post->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,','); ?>" />

再在header.php中<head></head>之间加入刚才展示的代码:

<title><?php bloginfo('name'); ?> <?php if ( is_single() ) { ?> &raquo; Blog Archive <?php } ?> <?php wp_title(); ?></title>
//刚才展示的胆码

Leave a Comment.