关注网络营销、社区化电子商务、品味生活
标签类目:乱码
2010-02-07网站运营

没有评论
107 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中乱码的问题。
返回顶部