个人
笔记网站
个人网站
wordpress 标题标签
首页 <title><?php bloginfo(‘name’); ?></title>
页面 <title><?php wp_title(); ?>-<?php bloginfo(‘name’); ?></title>
分类 <title><?php wp_title(); ?>-<?php bloginfo(‘name’); ?></title>
文章页 <title><?php bloginfo(‘name’); ?>-<?php wp_title(); ?></title>
文章页 <title><?php $category= get_the_category();  echo $category[0]->cat_name; ?>-<?php bloginfo(‘name’); ?>-<?php wp_title(); ?></title>
<?php
$keywords = ”;
$description = ”;
//文章页
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->post_content)),0,200);
}
}
}
//页面,添加自定义栏目keywords和description(关键字和描述)。
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();
}
//去掉两段空格
$keywords = trim(strip_tags($keywords));
$description = trim(strip_tags($description));
?>
<meta name=”keywords” content=”<?php echo $keywords; ?>” />
<meta name=”description” content=”<?php echo $description; ?>” />