post

WordPress博客标题优化

WordPress博客标题,效果为:
首页: 博客名称 | 副标题
分类: 分类名称 – 博客名称 | 副标题
文章: 文章名称 – 博客名称 | 副标题

<?php $theTitle=wp_title(" - ", false); if($theTitle != "") { ?><title><?php echo wp_title("",false); ?> - <?php bloginfo('name'); ?> | <?php bloginfo('description'); ?></title>
<?php } else { ?><title><?php bloginfo('name'); ?> | <?php bloginfo('description'); ?></title><?php } ?>

<?php if (is_home()){
    $description = "生活就像一盒巧克力,你永远不知道你会得到什么。";
    $keywords = "张衡,Henry,互联网,生活,技术,微博,京东";
} elseif (is_single()){
    if ($post->post_excerpt) {
        $description = $post->post_excerpt;
    } else {
        $description = substr(strip_tags($post->post_content),0,220);
    }
    $keywords = "";
    $tags = wp_get_post_tags($post->ID);
    foreach ($tags as $tag ) {
        $keywords = $keywords . $tag->name . ", ";
    }
}
?>
<meta name="keywords" content="<?=$keywords?>" />
<meta name="description" content="<?=$description?>" />

Comments

  1. 你的无觅相关文章的配图好神奇、。。

  2. 你的无觅相关文章的配图好神奇、。。

Speak Your Mind

*

· 789 次浏览