wpml_enqueued_browser_redirect_language
- Type
- action
- Category
- Site-Wide Language Information
- WPML Version
- 4.1.0
Description
This hook is executed at the end of the browser redirection PHP logic, after the wpml_browser_redirect_language_params and wpml_enqueue_browser_redirect_language filters. Despite its name, the action is fired even if wpml_enqueue_browser_redirect_language returns true.
Arguments
- $enqueued
- bool If true the script has been enqueued
- $params
- array Data with values, $pageLanguage, $languageUrls and $cookie.
- $pageLanguage string
- The language of the current page.
- $languageUrls array
- Associative array where the key is the language code and the values are the translated URLs of the current page.
- cookie
- Stores an associative array with the cookie settings. Please refer to Document.cookie for more details. The keys are:
- name: the name of the cookie (defaults to
_icl_visitor_lang_js). - domain: the domain in which the cookie must be used (defaults to the current domain and is not meant to be changed).
- path: the path of the cookie (defaults to
/). - expiration: the expiration in seconds is read from the value set in Remember visitors’ language preference that can be found in Browser language redirect on the WPML -> Languages.
- name: the name of the cookie (defaults to
Example usage
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 );
Related hooks
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