代码实现WordPress自动关键词keywords与描述description

下列编码完成的是以标识为关键字;以引言为叙述,要是没有填好引言,那么就全自动提取文章内容前200字为叙述。(实例教程转自:DeveWork)

编码完成WordPress全自动关键字与叙述:

下列编码放进你的主题风格下funtions.php的最后一个 ?>前:

  1. //全自动关键字与叙述 
  2. function get_cats_name() {
  3. $allcats=get_categories();
  4. foreach ($allcats as $category)
  5. {
  6. $keywords[] = $category->cat_name;
  7. }
  8. return $keywords;
  9. }
  10. // utf8 substr
  11. function utf8Substr($str$from$len) {
  12. return preg_replace(‘#^(?:[x00-x7F]|[xC0-xFF][x80-xBF] ){0,’.$from.’}’.
  13. ‘((?:[x00-x7F]|[xC0-xFF][x80-xBF] ){0,’.$len.’}).*#s’,
  14. $1‘,$str);
  15. }
  16. // Meta SEO
  17. function meta_SEO() {
  18. global $post;
  19. $output = ;
  20. if (is_single()){//如果是文章内容页
  21. $keywords = ;
  22. $description = ;
  23. if ($post->post_excerpt) {//假如文章内容引言存有就以文章内容引言为叙述
  24. $description = $post->post_excerpt;
  25. $description = str_replace(“rn”,“”,$description);
  26. $description = str_replace(“n”,“”,$description);
  27. $description = str_replace(“””,“‘”,$description);
  28. $description .= ‘…’;
  29. else {//假如文章内容引言不会有就断开文章内容前200字为叙述
  30. $description = utf8Substr(strip_tags($post->post_content),0,200);
  31. $description = str_replace(“rn”,“”,$description);
  32. $description = str_replace(“n”,“”,$description);
  33. $description = str_replace(“””,“‘”,$description);
  34. $description .= ‘…’;
  35. }
  36. $tags = wp_get_post_tags($post->ID);//取文章内容标识
  37. foreach ($tags as $tag ) {
  38. $keywordarray[] = $tag->name;
  39. }
  40. //以文章内容标识为关键词
  41. $keywords = implode(‘,’,array_unique((array)$keywordarray));
  42. else {//要不是文章内容页
  43. $keywords = ‘wordpress,wordpress主题风格,wordpress教程,wordpress主题下载,wordpressblog主题风格,wordpress公司主题风格,wordpress主题订制’; //在冒号间载入你blog的关键词用,断掉
  44. $description = ‘主题风格猫,专注于为众多网民给予全新最齐的wordpress主题风格’;//在冒号间载入你blog的简易叙述,不必过200字
  45. }
  46. //輸出关键词
  47. $output .= ‘<meta name=“keywords” content=“‘ . $keywords . ‘” />’ . “n”;
  48. $output .= ‘<meta name=“description” content=“‘ . $description . ‘” />’ . “n”;
  49. //輸出叙述
  50. echo “$outputn”;
  51. }
  52. add_action(‘wp_head’, ‘meta_SEO’);//加上meta_SEO函数公式到头顶部信息内容里

第43行与第44行的內容必须依据你的网址开展改动。

本文由网友投稿或「聚码源码网」整理自网络,如转载请注明出处:https://www.jumaniu.com/946/

本站发布的内容若侵犯到您的权益,请邮件联系 zhangqy2022#yeah.net 删除,我们将及时处理!

从您进入本站开始,已表示您已同意接受本站【免责声明】中的一切条款!

本站大部分下载资源收集于网络,不保证其完整性以及安全性,请下载后自行研究。

本站资源仅供学习和交流使用,版权归原作者所有,请在下载后24小时之内自觉删除。

若作商业用途,请购买正版,由于未及时购买和付费发生的侵权行为,使用者自行承担,概与本站无关。

常见问题
  • 本站所有资源解压密码为:www.jumaniu.com 或 www.tdji.cn
查看详情

相关文章

评论
暂无评论