由于wordpress默认是没有通过有效的对网页增加keywords和description这两个meta的功能,所以只好自己增加进来。 上次我发了一篇WordPress-plugins插件推荐,一个好的meta设置将有利于搜索引擎的优化。
1、meta:keywords的实现方式 我的Semcase Blog就是用这个Ultimate Tag Warrior Tag插件,研究一下它的后台都是用带链接的标签,在meta根本派不上用场。 在ultimate-tag-warrior.php文件中,加入以下代码: // edit by Abula function UTW_ShowTagsForCurrentPostAsKeywords(){ global $utw,$post; $format = array( ’single’=>’%tag%’, ‘first’=>’%tag%’, ‘default’=>’,%tag%’, ‘last’=>’,%tag%’); $utw->ShowTagsForPost($post->ID, $format, 0); } 在header.php中加入以下代码: 2、meta:description的实现方式 有关描述说明:对于主流搜索引擎收录方式最合适是在160个字符以内. 在wordpress发布文章里有个可选摘要功能, 系统直接读取里面的描述内容,如果没填将取文章的前220个字符为description的值. 在functions-post.php中加入以下代码: // edit by Abula function remove_html($text){ return preg_replace("’rn|n’",".", preg_replace("’<[/!]*?[^<>]*?>’","",$text) ); } function rb_show_excerpt($isRemove = true){ global $wp_query,$post; $temp = $wp_query->in_the_loop; if( !$temp){ have_posts(); the_post(); } $text = $post->post_excerpt; if( strlen($text) == 0){ $text = $post->post_content; $text = substr($text,0,160)."……"; } if( !$temp){ $wp_query->current_post–; $wp_query->post = $wp_query->posts[$wp_query->current_post]; $wp_query->in_the_loop = $temp; } if( isRemove){ return remove_html($text); } else{ return $text; } } 在header.php中加入以下代码:

