WPML
add_filter( 'wpml_is_redirected', 'callable $function_to_add, 10, 3 );
ประเภท
filter
หมวดหมู่
เบ็ดเตล็ด
เวอร์ชันของ WPML
4.0.0

คำอธิบาย

WPML จะพยายามเปลี่ยนเส้นทางผู้เยี่ยมชมไปยัง canonical URL โดยอัตโนมัติเมื่อพบข้อมูลที่ตรงกัน ฮุกนี้ช่วยให้สามารถปิดการใช้งานฟังก์ชันการทำงานนี้ของ WPML ได้

อาร์กิวเมนต์

มีพารามิเตอร์ 3 ตัวที่ถูกส่งไปยังฟิลเตอร์นี้
$redirect
(bool) ค่าบูลีนสำหรับกำหนดว่าจะปิดการใช้งานการดำเนินการเปลี่ยนเส้นทาง canonical URL ของ WPML หรือไม่
$post_id
(integer) ID ของโพสต์
$query
(array) อาร์เรย์คิวรีของ WordPress

ตัวอย่างการใช้งาน

ตัวอย่างต่อไปนี้จะป้องกันการเปลี่ยนเส้นทาง canonical URL ของ WPML สำหรับประเภทโพสต์แบบกำหนดเองที่มี slug เป็น “city”

function mytheme_do_not_redirect_city_post_type( $redirect, $post_id, $query ) {
    if ( 'city' === $query->get( 'post_type' ) ) {
       return false;
     }
    return $redirect;
    };
add_filter( 'wpml_is_redirected', mytheme_do_not_redirect_city_post_type, 10, 3 );

icl_ls_languages, wpml_sync_custom_field_copied_value, wpml_ls_enable_ajax_navigation, wpml_element_type, wpml_setting, wpml_sub_setting, wpml_exclude_post_from_auto_translate, wpml_forms_config_ninja-forms, wpml_forms_config_wpforms, wpml_tf_feedback_open_link

ฮุก เบ็ดเตล็ด ทั้งหมด 30 รายการ →