WordPress 增加 keywords 和 description 。
<?php
$keywords = '798资源网';
$description = '798资源网';
//文章页
if (is_single()){
//自定义栏目添加关键字和描述
$single_keywords = get_post_meta($post->ID, "keywords", true);
$description = get_post_meta($post->ID, "description", true);
//如果没设置自定义关键字,将使用标签作为关键字
if($single_keywords == ""){
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag){
$single_keywords = $single_keywords.$tag->name.",";
}
//去掉关键字前后的空白
$single_keywords = rtrim($single_keywords, ', ');
}
///如果文章关键字不为空
if($single_keywords){
$keywords = $single_keywords;
}
//自定义描述如果为空,将使用文章中的100个字作为描述
if($description == ""){
if($post->post_excerpt){
$description = $post->post_excerpt;
}else{
$description = mb_strimwidth(strip_tags(apply_filters('the_content',$post->