wpml_enqueued_browser_redirect_language
- 类型
- action
- 类别
- 全站语言信息
- WPML 版本
- 4.1.0
说明
此钩子在浏览器重定向 PHP 逻辑的末尾执行,位于 wpml_browser_redirect_language_params 和 wpml_enqueue_browser_redirect_language 过滤器之后。尽管名称如此,即使 wpml_enqueue_browser_redirect_language 返回 true,该操作也会被触发。
参数
- $enqueued
- bool 如果为 true,则表示脚本已加入队列
- $params
- array 包含 $pageLanguage、$languageUrls 和 $cookie 值的数据。
- $pageLanguage string
- 当前页面的语言。
- $languageUrls array
- 关联数组,其中键是语言代码,值是当前页面的已翻译 URL。
- cookie
- 存储包含 cookie 设置的关联数组。有关更多详情,请参考 Document.cookie。其键包括:
- name:cookie 的名称(默认为
_icl_visitor_lang_js)。 - domain:必须使用该 cookie 的域(默认为当前域,不建议更改)。
- path:cookie 的路径(默认为
/)。 - expiration:以秒为单位的过期时间,读取自 WPML -> 语言的浏览器语言重定向 中找到的记住访客的语言偏好设置值。
- name:cookie 的名称(默认为
使用示例
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