wordpress - 从 og :title Yoast seo plugin 中删除站点名称

标签 wordpress seo

我对 yoast seo 插件有疑问;我想从 og:title 中删除站点名称。

实际上,meta og:title 显示的内容是页面标题 - 站点标题。

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

如何删除站点名称,以便 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;
}

谢谢

最佳答案

在 Yoast SEO 插件中有一个过滤器可以用来修改 og 标题:wpseo_opengraph_title 将此函数添加到您的 functions.php。如有必要,替换分隔符。

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 ) ;

}

关于wordpress - 从 og :title Yoast seo plugin 中删除站点名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29437246/

相关文章:

google-analytics - 发送到 Twitter 进行登录时的跳出率?

javascript - 如何将 jquery 调整大小功能添加到 WP 谷歌地图插件?

php - Apache 服务器日志错误。 AH00126 : Invalid URI in request GET, 等

html - 编辑 Google 搜索为您的网站显示的段落

seo - 针对不同区域的 hreflang 等效方式是什么?

wordpress - 重写 Wordpress(翻译 slugs)的 URL 帖子格式(aside、link、gallery,...)

php - 将 robots.txt 重定向到 php 页面

wordpress - NextGEN Gallery 与 Roots Sage 主题冲突

php - WP AJAX : nonce works when logged out, 但登录时没有

javascript - Grunt、Compass、Foundation(foundationpress wordpress 主题)