/**
 * Default description property, using the excerpt or content for posts, or the
 * bloginfo description.
 */
function opengraph_default_description($description)
{
    if (empty($description)) {
        if (is_singular()) {
            $post = get_queried_object();
            if (!empty($post->post_excerpt)) {
                $description = strip_tags($post->post_excerpt);
            } else {
                // fallback to first 55 words of post content.
                $description = strip_tags(strip_shortcodes($post->post_content));
                $description = __opengraph_trim_text($description);
            }
        } else {
            if (is_author()) {
                $id = get_queried_object_id();
                $description = get_user_meta($id, 'description', true);
                $description = __opengraph_trim_text($description);
            } else {
                if (is_category() && category_description()) {
                    $description = category_description();
                    $description = __opengraph_trim_text($description);
                } else {
                    if (is_tag() && tag_description()) {
                        $description = tag_description();
                        $description = __opengraph_trim_text($description);
                    } else {
                        $description = get_bloginfo('description');
                    }
                }
            }
        }
    }
    return $description;
}
示例#2
0
/**
 * Default description property, using the excerpt or content for posts, or the
 * bloginfo description.
 */
function opengraph_default_description($description)
{
    if (empty($description)) {
        if (is_singular()) {
            $post = get_queried_object();
            if (!empty($post->post_excerpt)) {
                $description = $post->post_excerpt;
            } else {
                $description = $post->post_content;
            }
        } else {
            if (is_author()) {
                $id = get_queried_object_id();
                $description = get_user_meta($id, 'description', true);
            } else {
                if (is_category() && category_description()) {
                    $description = category_description();
                } else {
                    if (is_tag() && tag_description()) {
                        $description = tag_description();
                    } else {
                        if (is_archive() && function_exists("get_the_archive_description") && get_the_archive_description()) {
                            // new in version 4.1 to get all other archive descriptions
                            $description = get_the_archive_description();
                        } else {
                            $description = get_bloginfo('description');
                        }
                    }
                }
            }
        }
    }
    // strip description to first 55 words.
    $description = strip_tags(strip_shortcodes($description));
    $description = __opengraph_trim_text($description);
    return $description;
}