日志标签:Wordpress

WordPress SEO and Robots.txt File Tips

时间:2011年04月20日作者:Shieh查看次数: 396 views评论次数:0

WordPress robots.txt 文件的搜索引擎优化说明及技巧解析. 往下看之前, 先扫盲下 Robots.txt 文件的基础知识.
Robots.txt语法
Baidu Robots.txt
Google Robots.txt
Google:使用 robots.txt 文件拦截或删除网页

百度搜索帮助中心有一段感觉不是很靠谱的(http://www.baidu.com/search/robots.html)关于Robots.txt的说法:

搜索引擎使用spider程序自动访问互联网上的网页并获取网页信息。spider在访问一个网站时,会首先会检查该网站的根域下是否有一个叫做robots.txt的纯文本文件,这个文件用于指定spider在您网站上的抓取范围。您可以在您的网站中创建一个robots.txt,在文件中声明该网站中不想被搜索引擎收录的部分或者指定搜索引擎只收录特定的部分。

请注意,仅当您的网站包含不希望被搜索引擎收录的内容时,才需要使用robots.txt文件。如果您希望搜索引擎收录网站上所有内容,请勿建立robots.txt文件

言归正传, 下面是我的 WordPress Robots.txt 的写法:

User-agent: *
Disallow: /wp-admin
Disallow: /wp-includes
Disallow: /wp-content/plugins
Disallow: /wp-content/cache
Disallow: /wp-content/themes
Disallow: /comments/feed
Disallow: /category/*/*
Disallow: /category/
Disallow: /category/*/page/
Disallow: /page/
Disallow: /tag/
Disallow: */trackback
Disallow: */feed
Disallow: /*?*
Disallow: /*?
Disallow: /?s=
Allow: /wp-content/uploads
Sitemap: http://www.sinzi.org/sitemap.xml

User-agent: Googlebot
# disallow all files ending with these extensions
Disallow: /*.php$
Disallow: /*.js$
Disallow: /*.inc$
Disallow: /*.css$
Disallow: /*.gz$
Disallow: /*.wmv$
Disallow: /*.cgi$
Disallow: /*.xhtml$

WordPress Robots.txt 的写法, 根据自己的实际情况写吧.

WordPress Title, Keywords and Description SEO

时间:2011年04月20日作者:Shieh查看次数: 339 views评论次数:0

虽然市面上有很不错的 WordPress 标题 SEO 插件:All in One SEO Pack, HeadSpace 2 等, 但是我还是喜欢折腾用代码的方式去控制 WP 的 标题, 标签及描述等的SEO.

1. 我的 WordPress Title SEO 方式是在主题文件 header.php 里面写入下面的代码

<title><?php if (is_home()) {bloginfo('name');} else {echo trim(wp_title('',0));}?></title>

2. WordPress 关键词及描述

<?php
     //判断是否为首页
    if ( is_home ( ) )
    {
      $description = "英文SEO, 致力于Google, Yahoo, Bing and Baidu 等搜索引擎优化(SEO) 及折腾 WordPress, Drupal, ECMS!";
      $keywords = "英文SEO,Google SEO,Yahoo SEO,Bing SEO,Baidu SEO,搜索引擎优化";
    }
     //判断是否为文章页
    else if ( is_single () )
    {
      $description = wp_title(",",false,right).mb_substr(strip_tags($post->post_content),0,120,$encoding="UTF-8");
       //$description = mb_strimwidth(strip_tags(apply_filters('the_content',$post->post_content)),0,120);
      $keywords = "";
      $tags = wp_get_post_tags($post->ID);
      foreach ($tags as $tag ) {
      $keywords = $keywords . $tag->name . ",";
      }
      }
     //判断是否为分类页
    else if ( is_category( ) )
    {
      $description = strip_tags(category_description());
      $keywords = single_cat_title("", false);
    }
     //判断是否为标签页
    else if ( is_tag() )
    {
       $description = single_tag_title('SurDA',false);
       $description = "这里是标签[".$description."]下的所有文章";
       $keywords = single_tag_title('SurDA',false);
    }

    //其他都显示文章标题
    else {
        $description = wp_title("",false);
        $keywords = wp_title("",false);
    }
?>
<meta name="description" content="<?php echo $description ; ?>" />
<meta name="keywords" content="<?php echo $keywords ; ?>" />

3. 最后一步就是在主题的 Functions.php 中添加描述截取数及输出为utf-8的代码

if (!function_exists('mb_substr')) {
    function mb_substr($str, $start, $len = '', $encoding="UTF-8"){
        $limit = strlen($str);

        for ($s = 0; $start > 0;–$start) {// found the real start
            if ($s >= $limit)
                break;

            if ($str[$s] <= "\x7F")
                ++$s;
            else {
                ++$s; // skip length

                while ($str[$s] >= "\x80" && $str[$s] <= "\xBF")
                    ++$s;
            }
        }

        if ($len == '')
            return substr($str, $s);
        else
            for ($e = $s; $len > 0; –$len) {//found the real end
                if ($e >= $limit)
                    break;

                if ($str[$e] <= "\x7F")
                    ++$e;
                else {
                    ++$e;//skip length

                    while ($str[$e] >= "\x80" && $str[$e] <= "\xBF" && $e < $limit)
                        ++$e;
                }
            }
        return substr($str, $s, $e – $s);
    }
}

OK, 搞定. 参考了 SurDA Google Html建议 短的元说明 修善办法.

标签:,,分类:Web