wordpress 主题 header 优化方案改进版
星期日, 3月 15th, 2009针对wordpress主题的SEO优化方案,在网上流传的方案基础上进行了改进——
以下代码替代header.php文件相应代码:
- <title>
- <?php
- if (is_single() || is_page() || is_archive()) { wp_title(”,true) ; echo ‘ | ‘; }
- bloginfo(‘name‘);
- ?>
- </title>
- <?php
- //以下优化搜索引擎对导航页重复内容收录问题:
- if (is_single() || is_page() || is_home() )
- { echo ‘<meta name="robots" content="index,follow" />‘; }
- else
- { echo ‘<meta name="robots" content="noindex,follow" />‘; }
- //针对baidu对index不准确识别的问题则改用以下代码:
- //if ( !(is_home()) and !(is_single()) ) { echo ‘<meta name="Googlebot" content="noindex,follow" />’; }
- //以下优化description和keywords:
- if (is_single()) {
- if ($post->post_excerpt) {
- $description = $post->post_excerpt;
- } else {
- $description = substr(strip_tags($post->post_content),0,220);
- }
- $tags = wp_get_post_tags($post->ID);
- foreach ($tags as $tag ) {
- $keywords = $keywords . $tag->name . ", ";
- }
- } elseif(is_category()) {
- $description = category_description();
- }
- if ($keywords) {
- echo ‘<meta name="keywords" content="‘ . $keywords . ‘" />‘;
- }
- if ($description) {
- echo ‘<meta name="description" content="‘ . $description . ‘" />‘;
- } else {
- echo ‘<meta name="description" content="‘;
- bloginfo(‘description‘);
- echo ‘" />‘;
- }
- ?>



