Home > WordPress > WordPress的head优化

WordPress的head优化

其实这样的文章已经被写过好多次了.很多时候优化是通用的.我做些整理和说明,只针对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我一直很困惑.不知道如何处理.也许我因该去掉?请大家告诉我.

  1. Zoll Nov 30th, 2008 @ 00:58 | #1

    杀了个发 呵呵^^
    后面的优化已经调试成功,正是需要呢
    谢啦~

  2. Shawn Nov 30th, 2008 @ 01:46 | #2

    description 对 Google 很重要,keywords 才不重要, Google 根本就不考虑。

  3. xiaorsz Nov 30th, 2008 @ 02:02 | #3

    为什么想去掉哈!!倒想问下你是怎么加的,改代码?

  4. yinheli Nov 30th, 2008 @ 02:10 | #4

    @xiaorsz
    我是改的模板…用了这个主题后又看了些seo的东西.就照着改了.其实我也不知道应不应该去掉.加个那东西可能对留言者从某种程度上一种”打击”.尤其是对我这种本来就没有流量的小站.

    @Shawn
    呃.可能有的seo文章误导我了…反正我也懒的管了.呵呵,写些自己的文章.把那两项弄好.应该对排名有点好处.

  5. xiaorsz Nov 30th, 2008 @ 02:15 | #5

    @yinheli
    看来大家都是夜猫啊!!哈哈!!
    其实不会了,真正想留言的不会在乎这个的!!
    几乎大部分的博客留言都有nofollow的,不明白为什么这个模版没有!!

  6. yinheli Nov 30th, 2008 @ 02:17 | #6

    @xiaorsz
    因为mg12本人不想用吧.呵呵.他自己的就没有 我今天睡的多了.呵呵.现在还没有睡意.不过快睡了.呵呵

  7. stephen Nov 30th, 2008 @ 21:32 | #7

    我的header一直都是这样优化的。
    PS:貌似很多人都喜欢用这个主题,呵呵

  8. yinheli Nov 30th, 2008 @ 21:55 | #8

    @stephen
    这就是所谓’免费的商业主题’造成的泛滥…

  9. Yacca Dec 3rd, 2008 @ 22:24 | #9

    明白了,allinoneseo撤下…

  10. yinheli Dec 3rd, 2008 @ 22:31 | #10

    @Yacca
    能不用插件就不用插件了.

  11. Sayisee Dec 31st, 2008 @ 12:36 | #11

    Google过来的,祝考试顺利,呵呵。

  12. yinheli Jan 1st, 2009 @ 11:39 | #12

    @Sayisee
    Google还能找到这里?呵呵….我的网断了.一直没有上网.元旦出来奢侈一下.哈.
    你们什么时候考?也祝你考试顺利.

Submitting Comment, Give me a second...

Leave a comment

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
Trackbacks & Pingbacks ( 1 )
  1. Sep 4th, 2009 @ 14:58 | #1
    Pingback: Leaveoff's blog » WP手记:head优化