WordPress主题网站页面添加描述和关键词 php代码 包含搜索页 页面

最近在写wordpress 主题,然后再网上找回来的代码发现,没有搜索页及普通页面的 关键词及描述。下面我们对网上的代码进行补充。代码如下:

<title><?php wp_title( '_', true, 'right' ); ?></title>  <?php   if (is_home()){    	$keywords = $description = get_bloginfo('description');   } 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();   } elseif(is_search()) {      $keywords = $s;      $description = "Search result of ".$s;  }  $keywords = trim(strip_tags($keywords));   $description = trim(strip_tags($description));   ?>   <meta name="keywords" content="<?php echo $keywords; ?>" />   <meta name="description" content="<?php echo $description; ?>" />  <link rel="canonical" href="<?php echo get_permalink($post->ID);?>" />

欢迎各位大神做补充~

腾讯云限时秒杀【点击购买】

搬瓦工,CN2高速线路,1GB带宽,电信联通优化KVM,延迟低,速度快,建站稳定,搬瓦工BandwagonHost VPS优惠码BWH26FXH3HIQ,支持<支付宝> 【点击购买】!

Vultr$3.5日本节点,512M内存/500G流量/1G带宽,电信联通优化,延迟低,速度快【点击购买】!

阿里云香港、新加坡VPS/1核/1G/25G SSD/1T流量/30M带宽/年付¥288【点击购买】