从og标题中删除网站名称:标题Yoast seo插件
问题描述:
我对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;
}
谢谢
答
还有就是你可以用它来修改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) ;
}