WPML
ステータス
解決済み
解決されたバージョン
1.2.0
関連するプラグイン/テーマ
Yoast SEO

問題の概要

Yoast 14.xにおける最近の大幅な変更以降、一部のWPMLユーザーの環境で、Yoastのコンテンツが常にデフォルト言語で生成される現象が発生しています。

たとえば、セカンダリ言語のページにおいて、「og:title」や「og:description」などの「meta」タグ、またはパンくずリスト内のURLがこれに該当する場合があります。

回避策はありますが、問題の性質上、すべての環境で機能するとは限りません。現在、この問題の早期修正に向けて取り組んでいます。

Yoastコンテンツの翻訳で問題が発生している場合は、サポートにお問い合わせいただく前に、以下の回避策をお試しいただき、Yoast Multilingualの次期リリースをお待ちください。

回避策

お使いのテーマのfunctions.phpに以下のコードを追加します。

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

コードを追加した後、Yoast Test Helperプラグインをインストールします。
「ツール」 > 「Yoast Test」に移動し、「Reset Indexables tables & migrations」をクリックします。
最後に、ダッシュボードに移動し、サイトのインデックス作成を促す管理画面の通知をクリックします。

ご質問がある場合や関連する問題を報告する場合は、チームが効率的にサポートを提供できるよう、この既知の問題についてお知らせください。

すべての既知の問題 →