其实这样的文章已经被写过好多次了.很多时候优化是通用的.我做些整理和说明,只针对head部分.希望对刚用wordpress的有用.
分析head部分,无非就是keywords,description和title这三项对于搜索引擎比较重要.其中description对于Google来讲地位没有以前那么重要了.但是做些友好的修改还是比较好的.
知道要做的对象和目的,接下来就是写些代码.
关键字和描述部分
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | < ?php
if (is_home()) {
$description =“你的描述”;
$keywords = “你的关键字”;
} else if (is_single()) {
if ($post->post_excerpt) {
$description = $post->post_excerpt;
} else {
$description =mb_substr(strip_tags($post->post_content),0,210);
}
$keywords = "";
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag ) {
$keywords = $keywords.$tag->name.",";
}
} else if (is_category()) {
$keywords = “你的关键字”;
$description =category_description();
}else{
$keywords = “你的关键字”;
$description =“你的描述”;
}
?>
<meta name="keywords" content="<?php echo $keywords ?>" />
</meta><meta name="description" content="<?php echo $description ?>" />
</meta> |
然后处理标题部分:
Read more…