msgbartop
我们一起体验wordpress吧!
msgbarbottom
16 十二 08

wordpress的meta优化-Description和Keywords

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

<?if (is_home()){
    $description = "wordpress-Ing是一个介绍wordpress相关的博客,他的意图是收集blogger们需要的皮肤,推荐您更好的插件和一些代码改进.";
    $keywords = "WordPress, 博客, 互联网, 主题, 插件, 代码, blogger";
} 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?>" />

Tags: , , , ,

Reader's Comments

  1. |

    感谢,正要找这个

    [回复]

  2. |

    [...] 加速wordpress博客不光自己开着爽,而且也对seo(搜索引擎优化)起到决定性作用.所以加速wordpress博客势在必行!而缓存wordpress的数据库是必须的了,wordpress的数据库太需要优化了,也不知道官方什么时候把这些加入到官方版本上就好了… [...]

Leave a Comment