让wordpress博客自动添加关键词(keywords)及网页描述(description)
打开你的模板文件wp-content/themes/模板目录文件/header.php
在头部添加
<?php //判断是否为首页 if ( is_home ()) { $description = "这里填写博客首页的描述,最多220字符"; $keywords = "这里填写首页关键词,用英文逗号隔开"; //判断是否为文章页 } else if ( is_single ()) { if ( $post->post_excerpt) { $description = $post->post_excerpt; } else { $description = mb_strimwidth(strip_tags(apply_filters('the_content',$post->post_content) ),0,220); } $keywords = ""; $tags = wp_get_post_tags($post->ID); foreach ($tags as $tag ) { $keywords = $keywords.$tag->name.","; } //判断是否为分类页 } else if ( is_category()) { $description = category_description(); } ?>
注释可以删除
然后在
后面添加
<meta name = "keywords" content="<?php echo $keywords; ?>" /> <meta name= "description" content="<?php echo $description; ?> "/ >
保存文件,再刷新一下你的首页看看,是不是就可以了呢