511遇见 就没有没有利用插件来实现这一功能的,打开你的wourdpress头部文件header.php,加入以下代码:
<?php
if (is_home()){
$keywords = "WordPress主题,WordPress主题制作,WordPress插件,前端开发,javascript,jquery,div+CSS,css3,html5,bootstrap,图像印记";//换成你的网站的关键词
$description = "511遇见,不一样的遇见,是一个以wordpress,bootstrap,jQuery等前端技术交流建站的平台。";//换成你的网站的摘要描述
}
elseif (is_single()){
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag){
$keywords = $keywords.$tag->name.",";
}
$keywords = rtrim($keywords, ', ');
if($post->post_excerpt){
$description = $post->post_excerpt;
}else{
$description = mb_strimwidth(strip_tags(apply_filters('the_content',$post->post_content)),0,200);
}
}
elseif (is_page()){
$keywords = get_post_meta($post->ID, "keywords", true);
$description = get_post_meta($post->ID, "description", true);
}
elseif (is_category()){
$keywords = single_cat_title('', false);
$description = category_description();
}
elseif (is_tag()){
$keywords = single_tag_title('', false);
$description = tag_description();
}
$keywords = trim(strip_tags($keywords));
$description = trim(strip_tags($description));
?>
<meta name="keywords" content="<?php echo $keywords; ?>" />
<meta name="description" content="<?php echo $description; ?>" />