代码版优化WordPress的Description与Keywords
好记性不如烂笔头,今天记录一下诺豆网使用代码代替插件的方法来修改wordpress的description和keywords,算是为wordpress做个小优化吧!本部分代码参考了 我爱水煮鱼 我是如何 SEO WordPress 的 2:Description 和 Keywords 的方法!结合诺豆网的实际情况进行了具体化,记录一下吧!
<?php if (is_home()){ $nuodou_description = "诺豆网,记录技术与分享生活的原创博客"; $nuodou_keywords = "博客, 诺豆网"; } elseif (is_single()){ if ($post->post_excerpt) { $nuodou_description = $post->post_excerpt; } else { $nuodou_description = substr(strip_tags($post->post_content),0,220); } $nuodou_keywords = ""; $tags = wp_get_post_tags($post->ID); foreach ($tags as $tag ) { $nuodou_keywords = $nuodou_keywords . $tag->name . ", "; } } elseif (is_page()){ $nuodou_description = wp_title(''); $nuodou_keywords = ""; } elseif (is_category()){ $nuodou_description = single_cat_title(); $nuodou_keywords = ""; } elseif (is_month()){ $nuodou_description = the_time('F, Y'); $nuodou_keywords = ""; } elseif (is_day()){ $nuodou_description = the_time('F j, Y'); $nuodou_keywords = ""; } ?> <meta name="keywords" content="<?=$nuodou_keywords?>" /> <meta name="description" content="<?=$nuodou_description?>" />