public function og_title($echo = true)
{
$frontend = WPSEO_Frontend::get_instance();
$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);
$title = WPSEO_Meta::get_value('opengraph-title', $post_id);
if ($title === '') {
$title = $frontend->title('');
} else {
// Replace Yoast SEO Variables.
$title = wpseo_replace_vars($title, $post);
}
} else {
if (is_front_page()) {
$title = isset($this->options['og_frontpage_title']) && $this->options['og_frontpage_title'] !== '' ? $this->options['og_frontpage_title'] : $frontend->title('');
} elseif (is_category() || is_tax() || is_tag()) {
$title = WPSEO_Taxonomy_Meta::get_meta_without_term('opengraph-title');
if ($title === '') {
$title = $frontend->title('');
} else {
// Replace Yoast SEO Variables.
$title = wpseo_replace_vars($title, $GLOBALS['wp_query']->get_queried_object());
}
} else {
$title = $frontend->title('');
}
}
/**
* Filter: 'wpseo_opengraph_title' - Allow changing the title specifically for OpenGraph
*
* @api string $unsigned The title string
*/
$title = trim(apply_filters('wpseo_opengraph_title', $title));
if (is_string($title) && $title !== '') {
if ($echo !== false) {
$this->og_tag('og:title', $title);
return true;
}
}
if ($echo === false) {
return $title;
}
return false;
}