VPS参考、测评、推荐
分享你关注的VPS主机优惠信息

草根吧VPS_WordPress技巧分享_纯代码自动为wordpress站点/文章添加关键词与描述

草根吧VPS_WordPress技巧分享_纯代码自动为wordpress站点/文章添加关键词与描述

网站的关键性字以及网页描述关系网站对于搜索引擎的友谊程度,假如自己手动加似乎甚折腾了,那让wordpress博客手动作为每篇文章手动关键性字以及网页描述

每篇文章的内容有所,我们该让wordpress手动文章描述与关键词呢?下面便让我们来看如何予wordpress手动文章描述与关键词

方法1,直接打开文件下header.文件

ID, "description", true);     $description2 = str_replace("n","",mb_strimwidth(strip_tags($post->post_content), 0, 200, "…", 'utf-8'));     // 填写自定义字段description时显示自定义字段的内容,否则使用文章内容前200字作为描述     $description = $description1 ? $description1 : $description2;     // 填写自定义字段keywords时显示自定义字段的内容,否则使用文章tags作为关键词     $keywords = get_post_meta($post->ID, "keywords", true);     if($keywords == '') {        $tags = wp_get_post_tags($post->ID);        foreach ($tags as $tag ) {           $keywords = $keywords . $tag->name . ", ";        }        $keywords = rtrim($keywords, ', ');     }  }  elseif (is_category()) {     // 分类的description可以到后台 - 文章 -分类目录,分类的描述     $description = category_description();     $keywords = single_cat_title('', false);  }  elseif (is_tag()){     // 标签的description可以到后台 - 文章 - 标签,标签的描述     $description = tag_description();     $keywords = single_tag_title('', false);  }  $description = trim(strip_tags($description));  $keywords = trim(strip_tags($keywords));  ?>  

方法2,在你的functions.php文件添加以下

add_action ( 'wp_head', 'wp_keywords' ); // 添加关键字  add_action ( 'wp_head', 'wp_description' ); // 添加页面描述      function wp_keywords() {   global $s, $post;   $keywords = '';   if (is_single ()) { //如果是文章页,关键词则是:标签+分类ID   if (get_the_tags ( $post->ID )) {    foreach ( get_the_tags ( $post->ID ) as $tag )    $keywords .= $tag->name . ', ';   }   foreach ( get_the_category ( $post->ID ) as $category )    $keywords .= $category->cat_name . ', ';   $keywords = substr_replace ( $keywords, '', - 2 );   } elseif (is_home ()) {   $keywords = '我是主页关键词'; //主页关键词   } elseif (is_tag ()) { //标签页关键词   $keywords = single_tag_title ( '', false );   } elseif (is_category ()) {//分类页关键词设置   $keywords = single_cat_title ( '', false );   } elseif (is_search ()) {//搜索页关键词设置   $keywords = esc_html ( $s, 1 );   } else {//默认页关键词设置   $keywords = trim ( wp_title ( '', false ) );   }   if ($keywords) { //输出关键词   echo "n";   }  }     function wp_description() {   global $s, $post;   $description = '';   $blog_name = get_bloginfo ( 'name' );   if (is_singular ()) { //文章页如果存在描述字段,则显示描述,否则截取文章内容   if (! empty ( $post->post_excerpt )) {    $text = $post->post_excerpt;   } else {    $text = $post->post_content;   }   $description = trim ( str_replace ( array (    "rn",    "r",    "n",    " ",    " "   ), " ", str_replace ( """, "'", strip_tags ( $text ) ) ) );   if (! ($description))    $description = $blog_name . "-" . trim ( wp_title ( '', false ) );   } elseif (is_home ()) {//显示描述设置   $description = $blog_name . "-" . get_bloginfo ( 'description' ) .'要显示的描述'; // 首頁要自己加   } elseif (is_tag ()) {//标签页显示描述设置   $description = $blog_name . "有关 '" . single_tag_title ( '', false ) . "' 的文章";   } elseif (is_category ()) {//分类页显示描述设置   $description = $blog_name . "有关 '" . single_cat_title ( '', false ) . "' 的文章";   } elseif (is_archive ()) {//文档页显示描述设置   $description = $blog_name . "在: '" . trim ( wp_title ( '', false ) ) . "' 的文章";   } elseif (is_search ()) {//搜索页显示描述设置   $description = $blog_name . ": '" . esc_html ( $s, 1 ) . "' 的搜索結果";   } else {//默认其他页显示描述设置   $description = $blog_name . "有关 '" . trim ( wp_title ( '', false ) ) . "' 的文章";   }   //输出描述   $description = mb_substr ( $description, 0, 220, 'utf-8' ) . '..';   echo "n";  }

 

:草根吧VPS_WordPress技巧分享_纯为wordpress站点/文章添加关键词与描述,://vps.caogenba../1202.html

赞(0) 打赏
未经允许不得转载:草根吧VPS_最新VPS信息参考 » 草根吧VPS_WordPress技巧分享_纯代码自动为wordpress站点/文章添加关键词与描述
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址