- Status
- Resolved
- Resolved in
- 1.2.0
- Related plugin/theme
- Yoast SEO
Overview of the issue
After recent major changes in Yoast 14.x, some WPML users are seeing Yoast content always being generated in the default language.
For example, on a page in a secondary language, this could be “meta” tags like “og:title” or “og:description”, or the URLs in your breadcrumbs.
We have a workaround but due to the nature of the problem, it may not work for everyone. We are working to fix this issue as soon as possible.
If you are experiencing trouble translating Yoast content, please try the workaround below and wait for the next release of Yoast Multilingual before creating a support ticket.
Workaround
Add to your theme functions.php this code:
if ( ! is_admin() ) {
add_filter( 'wpseo_title', 'wpml_wpseo_title', 10, 2 );
add_filter( 'wpseo_opengraph_title', 'wpml_wpseo_title', 10, 2 );
}
function wpml_wpseo_title( $title, $presentation ) {
switch ( $presentation->model->object_type ) {
case 'post-type-archive':
$key = 'title-ptarchive-' . $presentation->model->object_sub_type;
break;
case 'system-page':
$key = 'title-' . $presentation->model->object_sub_type . '-wpseo';
break;
default:
$key = false;
}
if ( $key ) {
$option = get_option( 'wpseo_titles' );
if ( isset( $option[ $key ] ) ) {
$title = wpseo_replace_vars( $option[ $key ], $presentation );
}
}
return $title;
}
if ( ! is_admin() ) {
add_filter( 'wpseo_metadesc', 'wpml_wpseo_desc', 10, 2 );
add_filter( 'wpseo_opengraph_desc', 'wpml_wpseo_desc', 10, 2 );
}
function wpml_wpseo_desc( $title, $presentation ) {
switch ( $presentation->model->object_type ) {
case 'post-type-archive':
$key = 'metadesc-ptarchive-' . $presentation->model->object_sub_type;
break;
case 'system-page':
$key = 'metadesc-' . $presentation->model->object_sub_type . '-wpseo';
break;
default:
$key = false;
}
if ( $key ) {
$option = get_option( 'wpseo_titles' );
if ( isset( $option[ $key ] ) ) {
$title = wpseo_replace_vars( $option[ $key ], $presentation );
}
}
return $title;
}
add_filter( 'wpseo_save_indexable', function( $indexable ) {
$args = [
'element_id' => $indexable->object_id,
'element_type' => $indexable->object_type,
];
$language_code = apply_filters( 'wpml_element_language_code', false, $args );
$indexable->permalink = apply_filters( 'wpml_permalink', $indexable->permalink, $language_code, true );
return $indexable;
} );
After adding the code, install the Yoast Test Helper plugin.
Go to Tools > Yoast Test and click in “Reset Indexables tables & migrations”.
Finally, go to your Dashboard and click on the admin notice that prompts you to index the site.
If you have any questions or wish to report a related problem, please do mention this known issue so that our team can provide you with efficient support.