- สถานะ
- แก้ไขแล้วโดยผู้พัฒนา
- รายงานสำหรับ
- WPML SEO 2.0.1
ภาพรวมของปัญหา
นี่คือปัญหาทั่วไปของ Yoast SEO (ไม่ได้เกิดขึ้นเฉพาะกับ WPML) และมีการรายงานไว้ที่นี่
หากคุณจัดรูปแบบ URL เพื่อแสดงภาษาเป็นพารามิเตอร์ใน WPML → ภาษา คุณจะสังเกตเห็นว่าหน้าในภาษารองที่มีการแบ่งหน้าจะแสดงลิงก์ Canonical ที่ไม่ถูกต้อง
วิธีแก้ปัญหาชั่วคราว
โปรดสำรองข้อมูลไซต์ของคุณทั้งหมดก่อนดำเนินการต่อ จากนั้นเพิ่มโค้ดต่อไปนี้ลงในไฟล์ธีม 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 );
