public function description($echo = true)
{
$ogdesc = '';
$frontend = WPSEO_Frontend::get_instance();
if (is_front_page()) {
if (isset($this->options['og_frontpage_desc']) && $this->options['og_frontpage_desc'] !== '') {
$ogdesc = wpseo_replace_vars($this->options['og_frontpage_desc'], null);
} else {
$ogdesc = $frontend->metadesc(false);
}
}
$is_posts_page = $frontend->is_posts_page();
if (is_singular() || $is_posts_page) {
$post_id = $is_posts_page ? get_option('page_for_posts') : get_the_ID();
$post = get_post($post_id);
$ogdesc = WPSEO_Meta::get_value('opengraph-description', $post_id);
// Replace Yoast SEO Variables.
$ogdesc = wpseo_replace_vars($ogdesc, $post);
// Use metadesc if $ogdesc is empty.
if ($ogdesc === '') {
$ogdesc = $frontend->metadesc(false);
}
// Tag og:description is still blank so grab it from get_the_excerpt().
if (!is_string($ogdesc) || is_string($ogdesc) && $ogdesc === '') {
$ogdesc = str_replace('[…]', '…', strip_tags(get_the_excerpt()));
}
}
if (is_category() || is_tag() || is_tax()) {
$ogdesc = WPSEO_Taxonomy_Meta::get_meta_without_term('opengraph-description');
if ($ogdesc === '') {
$ogdesc = $frontend->metadesc(false);
}
if ($ogdesc === '') {
$ogdesc = trim(strip_tags(term_description()));
}
if ($ogdesc === '') {
$ogdesc = WPSEO_Taxonomy_Meta::get_meta_without_term('desc');
}
}
// Strip shortcodes if any.
$ogdesc = strip_shortcodes($ogdesc);
/**
* Filter: 'wpseo_opengraph_desc' - Allow changing the OpenGraph description
*
* @api string $ogdesc The description string.
*/
$ogdesc = trim(apply_filters('wpseo_opengraph_desc', $ogdesc));
if (is_string($ogdesc) && $ogdesc !== '') {
if ($echo !== false) {
$this->og_tag('og:description', $ogdesc);
}
}
return $ogdesc;
}