其实这样的文章已经被写过好多次了.很多时候优化是通用的.我做些整理和说明,只针对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 | <?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 name="description" content="<?php echo $description ?>" /> |
然后处理标题部分:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <title> <?php if(is_home()){ bloginfo('name');echo " | Yinheli's blog"; }else if (is_category()){ single_cat_title();echo " | Yinheli's blog"; }else if (is_search()){ bloginfo('name'); echo " search results: ";echo wp_specialchars($s); }else if(is_tag()){ wp_title('',true);echo " | yinheli's blog"; }else{ wp_title('',true); }?> </title> |
关于标题部分用”|””-”都可以.随你喜欢了.但是不提倡用奇怪的字符.包括’_’(下划线在内)
Ps.
关于评论的nofollow我一直很困惑.不知道如何处理.也许我因该去掉?请大家告诉我.
声明:本站遵循署名-非商业性使用-相同方式共享3.0共享协议. 转载请注明转自 PhilNa ™
杀了个发 呵呵^^
后面的优化已经调试成功,正是需要呢
谢啦~