2015-04-03 55 views
0

我對yoast seo插件有問題;我想從og:title中刪除sitename。從og標題中刪除網站名稱:標題Yoast seo插件

實際上,meta og:title顯示的是網頁標題 - 網站標題的內容。

<meta property="og:title" content="The title of the page or blog - The title of the site" /> 

我怎樣才能刪除sitename,所以og:title只顯示頁面或博客的標題?

public function og_title($echo = true) { 
    if (is_singular()) { 
     $title = WPSEO_Meta::get_value('opengraph-title'); 
     if ($title === '') { 
      $title = WPSEO_Frontend::get_instance()->title(''); 
     } 
     else { 
      // Replace WP SEO Variables 
      $title = wpseo_replace_vars($title, get_post()); 
     } 
    } 
    else if (is_front_page()) { 
     $title = ($this->options['og_frontpage_title'] !== '') ? $this->options['og_frontpage_title'] : WPSEO_Frontend::get_instance()->title(''); 
    } 
    else { 
     $title = WPSEO_Frontend::get_instance()->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; 
} 

謝謝

回答

0

還有就是你可以用它來修改OG冠軍Yoast SEO插件過濾器:wpseo_opengraph_title 此功能添加到您的functions.php。如有必要,請替換sepparator字符。

add_filter('wpseo_opengraph_title','mysite_ogtitle', 999); 
function mysite_ogtitle($title) { 

    $sepparator = " - "; 
    $the_website_name = $sepparator . get_bloginfo('name'); 
    return str_replace($the_website_name, '', $title) ; 

}