wordpress文章添加keywords和description有利seo优化

wordpress搭建的网站Seo是个技术活,众多seo插件可供你选择。你还需要勤奋地原创更新文章,提高搜索引擎抓取量。我所使用的devework付费主题,只在后台界面设置首页的keywords和description,但文章页面源码并没有上述字段内容。基于我爱水煮鱼的代码,我做了一点修改,在wordpress后台-外观-编辑-header.php的<head></head>字段中间添加以下代码:

<?if (is_home()){
$description = “替换成你的网站描述”;
$keywords = “替换成你的网站关键词”;
} elseif (is_single()){
if ($post->post_excerpt) {
$description = $post->post_excerpt;
} else {
$description = substr(strip_tags($post->post_content),0,500);
}

$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?>” />

如果你的文章没有设置摘要字段,自动截取文章前500个字符做为描述。文章标签做为关键词。

One thought on “wordpress文章添加keywords和description有利seo优化

  1. Pingback: vvv | 诚汇投资
  2. 嗯……这篇文章已经好久了……
    还是想问一下,在wp后台应用这段代码的时候,会提示syntax error, unexpected ‘,’的错误,这个具体是怎么回事呢……为什么我这边不能用英文逗号分开关键词……百度无解

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.