WPSEO_OpenGraph::og_title PHP Méthode

og_title() public méthode

Outputs the SEO title as OpenGraph title.
public og_title ( boolean $echo = true ) : string | boolean
$echo boolean Whether or not to echo the output.
Résultat string | boolean
    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;
    }

Usage Example

 /**
  * @covers WPSEO_OpenGraph::og_title
  */
 public function test_og_title()
 {
     // create and go to post
     $post_id = $this->factory->post->create();
     $this->go_to(get_permalink($post_id));
     $expected_title = self::$class_instance->title('');
     $expected_html = '<meta property="og:title" content="' . $expected_title . '" />' . "\n";
     $this->assertTrue(self::$class_instance->og_title());
     $this->expectOutput($expected_html);
     $this->assertEquals(self::$class_instance->og_title(false), $expected_title);
 }
All Usage Examples Of WPSEO_OpenGraph::og_title