wordpress无插件根据不同的页面自动生成关键词keywordps摘要description

511遇见 就没有没有利用插件来实现这一功能的,打开你的wourdpress头部文件header.php,加入以下代码:

  1. <?php
  2. if (is_home()){
  3. 	$keywords = "WordPress主题,WordPress主题制作,WordPress插件,前端开发,javascript,jquery,div+CSS,css3,html5,bootstrap,图像印记";//换成你的网站的关键词
  4. 	$description = "511遇见,不一样的遇见,是一个以wordpress,bootstrap,jQuery等前端技术交流建站的平台。";//换成你的网站的摘要描述
  5. }
  6. elseif (is_single()){
  7. 	$tags = wp_get_post_tags($post->ID);
  8. 	foreach ($tags as $tag){
  9. 		$keywords = $keywords.$tag->name.",";
  10. 	}
  11. 	$keywords = rtrim($keywords, ', ');
  12. 	if($post->post_excerpt){
  13. 		$description = $post->post_excerpt;
  14. 	}else{
  15. 		$description = mb_strimwidth(strip_tags(apply_filters('the_content',$post->post_content)),0,200);
  16. 	}
  17. }
  18. elseif (is_page()){
  19. 	$keywords = get_post_meta($post->ID, "keywords", true);
  20. 	$description = get_post_meta($post->ID, "description", true);
  21. }
  22. elseif (is_category()){
  23. 	$keywords = single_cat_title('', false);
  24. 	$description = category_description();
  25. }
  26. elseif (is_tag()){
  27. 	$keywords = single_tag_title('', false);
  28. 	$description = tag_description();
  29. }
  30. $keywords = trim(strip_tags($keywords));
  31. $description = trim(strip_tags($description));
  32. ?>
  33. <meta name="keywords" content="<?php echo $keywords; ?>" />
  34. <meta name="description" content="<?php echo $description; ?>" />

发布日期:

所属分类: Wordpress, Wordpress 插件 标签:    


没有相关文章!