问题概述
使用 Yoast SEO 时,插件会自动将 Open Graph 元标签添加到作者归档页面的 head 部分。但是,在翻译后的作者归档页面上,og:url 元标签将显示默认语言的 URL。
临时解决方法
这个问题已修复。 更新到最新版本即可在您的站点上解决此问题,因此,只有当您暂时无法更新时,才需要此临时解决方法。
在继续操作之前,请确保拥有完整的站点备份。
- 打开您主题的 functions.php 文件。PHP
/** * Workaround to fix og:url meta tag on translations of author archives */ add_filter( 'wpseo_opengraph_url', function($url, $presentation){ if ( $presentation instanceof YoastWPSEOPresentationsIndexable_Author_Archive_Presentation ){ $user_id = $presentation->source['post_author']; $url = rawurlencode( get_author_posts_url($user_id) ); } return $url; }, 10, 2 );