wordpress keyword and description
Now, I present a idea from neoease wordpress theme. First, let’s look at the code. This code is added on header.php :
<?php
if (is_home()) {
$description = “wordpress description”;
$keywords = “wordpress keywords”;
} else if (is_single()) {
$description = $post->post_title .” | “. mb_substr(strip_tags($post->post_content),0,150,’UTF-8′).”…” ;
$keywords = “”;
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag ) {
$keywords = $keywords . $tag->name . “, “;
}
} else if (is_category()) {
$description = category_description();
}
$description = str_replace(array(“\r\n”,”\r”,”\n”,” “),”",$description);
?>
<meta name=”keywords” content=”<?php echo $keywords; ?>” />
<meta name=”description” content=”<?php echo $description; ?>” />
<title><?php bloginfo(‘name’); ?><?php wp_title(); ?></title>
<?php if(is_single()){?><link rel=”canonical” href=”<?php the_permalink() ?>” /><?php } ?>
If it is at home page, it will show what you writed. For example, it will show wordpress description. The same as keywords. If it is at single page, the description will show your post title and your post content which it will be cut from 0 to 150 words. The keyword will be your tags. If it is at category, the description will be category description but no keywords. Moreover, if visitors is at single page, the title will be your post title name and your blog name. If at home, will be only your blog name, for instant 八所物语.
This code can work at any wordpress themes. I don’t like use the seo in all plugin, it let my keywords and description be messy code. Simple way give you big effection. Please try, you will enjoy it.
声明: 原创文章,转载请注明转自 8suo -> wordpress keyword and description

不过用了ALL IN ONE SEO就最好别添加这个,似乎两个会冲突
SIMPLE TAG里面也有注明这点
这当然,我用ALL IN ONE SEO 在代码页面会出现乱码,再说我不想装那么多插件。
这样更好,我看我的代码就比较烦,TITLE在开头,而KEYWORD,描述都离特别远,好在不影响收录