WPML
ステータス
開発者により解決済み
報告対象
WPML SEO 2.0.1

問題の概要

これはYoast SEOの一般的な問題であり(WPMLに特有のものではありません)、こちらで報告されています

WPML言語で、言語をパラメーターとして表示するようにURLをフォーマットしている場合、ページ分割されたセカンダリ言語のページに誤ったカノニカルリンクが表示されます。

回避策

続行する前に、サイトの完全なバックアップを作成してください。その後、お使いのテーマのfunctions.phpファイルに以下のコードを追加してください:

 
// define the wpseo_canonical callback 
function wpmldp_filter_wpseo_canonical_lang_parameter_position( $canonical ) { 
        // decode URL
        $canonical = urldecode($canonical);
	
	// get current language
	$my_current_lang = apply_filters( 'wpml_current_language', NULL );
	
	// define ?lang parameter
	$param = '?lang='.$my_current_lang;
	
	// check if current $canonical contains the parameter
	if(strpos($canonical, $param) !== false){
		
		// remove the parameter from URL
		$canonical = str_replace('/'.$param, "", $canonical);
		
		// add it again
		$canonical = $canonical.$param;
	}	
	
    return $canonical; 
}; 
         
// add the filter 
add_filter( 'wpseo_canonical', 'wpmldp_filter_wpseo_canonical_lang_parameter_position', 999 ); 

すべての既知の問題 →