博客 » WordPress » 我是如何 SEO WordPress 的 2:Description 和 Keywords

我是如何 SEO WordPress 的 2:Description 和 Keywords

Denis 2008年11月16日

Description 和 Keywords 的重要性已经不像以前那么重要了,但是设置正确的 Description 和 Keywords 还是对你的排名有利。

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

<?if (is_home()){
    $description = "我爱水煮鱼是一个关注 WordPress 开源博客平台应用和互联网的 IT 博客。";
    $keywords = "WordPress, 博客, 互联网, 主题, 插件";
} 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="keywords" content="<?=$keywords?>" />
<meta name="description" content="<?=$description?>" />

上面代码请放到 header.php 相应的位置,同样我也只优化了首页和日志页面。

标签:

55 条评论 添加你的评论 →

发表评论

你必须 登陆 之后才能留言。你可以使用以下方式快速登陆我爱水煮鱼:

你也可选择直接在本站 注册


订阅我爱水煮鱼 denishua / Twitter denishua / linkedin WordPress 企业站点建设

赞助商

快速导航

WordPress 案例

WordPress 技巧分享