WordPress文章描述

WordPress文章描述

//seo 代码
function bigfa_description() {
    global $s, $post;
    $description = '';
    $blog_name = get_bloginfo('name');
    if ( is_singular() ) {
        $ID = $post->
        ID;
        $title = $post->
        post_title;
        $author = $post->
        post_author;
        $user_info = get_userdata($author);
        $post_author = $user_info->
        display_name;
        if (!get_post_meta($ID, "meta-description", true)) {
            $description = $title.' - 作者: '.$post_author.',首发于'.$blog_name;
        } else {
            $description = get_post_meta($ID, "meta-description", true);
        }
    } elseif ( is_home () ) {
        $description = "我是博客首页的描述,么么哒";
        // 首页要自己加,如果你主题有后台设置可以连接上
    } elseif ( is_tag() ) {
        $description = single_tag_title('', false) . " - ". trim(strip_tags(tag_description()));
    } elseif ( is_category() ) {
        $description = single_cat_title('', false) . " - ". trim(strip_tags(category_description()));
    } 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 "<meta name="description" content="$description">n";
}
add_action('wp_head','bigfa_description');

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据