WordPress博客添加meta标签的方法
严重浪漫在用站长工具测试时,看到测试结果里,本博客的META信息不完整,没有关键词(KeyWords)、描述(Description)。如图:
为了SEO,赶快添加META标签啊。方法如下。
进入Wordpress的后台→外观→编辑,找到header.php。在编辑栏里找到
1 | < meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ /> |
这一句,在它后面添加如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?if (is_home()){ $keywords = "XXX,XXX,XXX"; $description = "简要描述一下你的博客"; } 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?>" /> |
也有人说,这段代码放到< head>< /head>之间之间就可以了。
其中,修改 keywords= “XXX,XXX,XXX”为你自己的首页关键字,修改 description = “简要描述一下你的博客”为你自己的首页描述。“220”是描述(Description)的最大长度。
本文参考自:
WordPress SEO 之 Meta 信息(万戈)
为wordpress添加meta标签(懒猫)
【附】
站长工具–META测试
学习啦.. 开始还不理解..
用个seo插件一切都搞定了