关注网络营销、社区化电子商务、品味生活
« »
2010年02月7日网站运营

105 views

给wordpress主页(首页)添加keywords和description

wordpress安装后,主页默认是没有meta的keywords和description选项,需要自己手动添加,我们就能解决了。

在主题目录下先找到的header.php文件,然后在文件找到

<title><?php bloginfo('name'); ?><?php wp_title(); ?></title>

在该行之上添加如下代码:

<?php if (is_home()){
    $description = "Google Support Blog Focus on Google technology!";
    $keywords = "Google Docs,Google Chrome,Chrome theme,Chrome plugin,Google Analystic";
} elseif (is_single()){
    $description =  mb_substr(strip_tags($post->post_content),0,110,utf8);
    $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?>" />

其中红色的代码可以解决description中乱码的问题。

日志信息 »

该日志于2010-02-07 18:57由 mood 发表在网站运营分类下, 你可以发表评论。除了可以将这个日志以保留源地址及作者的情况下引用到你的网站或博客,还可以通过RSS 2.0订阅这个日志的所有评论。

相关日志 »

  • 暂无相关日志

没有评论

发表评论 »

返回顶部