wordpress seo head区代码

2013-11-6 chenmo wordpress

<?php if (is_home()){
    $keywords = get_option('mytheme_keywords');;
    $description = get_option('mytheme_description');
} 
elseif (is_single()){
    if ($post->post_excerpt) {
        $description = $post->post_excerpt;
    } else {
        $description = mb_substr(strip_tags($post->post_content),0,120,'utf-8');
    }
    $keywords = "";      
    $tags = wp_get_post_tags($post->ID);
    foreach ($tags as $tag ) {
        $keywords = $keywords . $tag->name . ", ";
    }
}
elseif(is_category()) {
    $description = '有关 '.single_cat_title( '', false ).' 的全部文章';
    $keywords = single_cat_title( '', false );
}
elseif(is_tag()) {
    $description = '有关 '.single_cat_title( '', false ).' 的全部文章';
    $keywords = single_cat_title( '', false );
}
?>
<meta name="keywords" content="<?php echo $keywords;?>" />
<meta name="description" content="<?php echo $description;?>" />

又在网上找了一个

标签: wordpress SEO Head

Powered by emlog 湘ICP备13007859号 空间由景安网络赞助