WPML
wpml_enqueued_browser_redirect_language
Loại
action
Phiên bản WPML
4.1.0

Miêu tả

hook này được thực thi ở cuối logic PHP chuyển hướng trình duyệt, sau các bộ lọc wpml_browser_redirect_language_params và wpml_enqueue_browser_redirect_language. Bất chấp tên gọi của nó, hành động này vẫn được kích hoạt ngay cả khi wpml_enqueue_browser_redirect_language trả về true.

Tham số

$enqueued
bool Nếu đúng, tập lệnh đã được đưa vào hàng đợi
$params
array Dữ liệu chứa các giá trị $pageLanguage, $languageUrls và $cookie.
$pageLanguage string
Ngôn ngữ của trang hiện tại.
$languageUrls array
Mảng kết hợp trong đó khóa là mã ngôn ngữ và các giá trị là các URL đã dịch của trang hiện tại.
cookie
Lưu trữ một mảng kết hợp chứa các cài đặt cookie. Vui lòng tham khảo Document.cookie (mở trong tab mới) để biết thêm chi tiết. Các khóa là:
  • name: tên của cookie (mặc định là _icl_visitor_lang_js).
  • domain: miền mà cookie phải được sử dụng (mặc định là miền hiện tại và không dành cho việc thay đổi).
  • path: đường dẫn của cookie (mặc định là /).
  • expiration: thời gian hết hạn tính bằng giây được đọc từ giá trị thiết lập trong Ghi nhớ tùy chọn ngôn ngữ của khách truy cập, có thể tìm thấy trong Chuyển hướng ngôn ngữ trình duyệt tại WPMLCài đặtNgôn ngữ.

Ví dụ sử dụng

function override_browser_redirect( $enqueued, $params ) {
    if ( ! $enqueued ) {
        // E.g.: A script which uses IP geolocalization
        wp_enqueue_script( 'my-custom-script', 'url/to/custom.script.js' );
        
        // Pass the `$params` array to the script, so it can use it to find the best match
        wp_localize_script( 'my-custom-script', 'params', $params );
    }
}

add_action( 'wpml_enqueued_browser_redirect_language', 'override_browser_redirect', 10, 2 );

wpml_decode_custom_field, wpml_footer_language_selector, wpml_add_language_form_field, wpml_ls_exclude_in_menu, wpml_is_rtl, wpml_alternate_hreflang, wpml_head_langs, wpml_must_translate_canonical_url, wpml_browser_redirect_language_params, wpml_active_languages

Tất cả 30 hook Thông tin ngôn ngữ toàn trang web