availability:

WPML Version: Coming soon!

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.

type:
action
category:
Site-Wide Language Information
parameters:
$enqueued
bool If true the script has been enqueued
$params
array Data with values, $pageLanguage, $languageUrls and $cookie.

$pageLanguagestring

The language of the current page.

$languageUrlsarray

Associative array where the key is the language code and the values are the translated URLs of the current page.

$cookieStores 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.
hook 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 );