availability:

WPML Version: 4.0.6

description:

This filter can be used when the theme developer wants to use a different cookie name or tweak the languageUrls array to use different URLs.

It uses the $params argument which is an associative array containing some information about the current language, the active languages and the cookie settings.

type:
filter
category:
Site-Wide Language Information
parameters:
pageLanguage
Stores the current language code.
languageUrls
Stores an associative array containing all the current page’s translation URLs. The keys of the array are the language codes. The same language can have multiple entries to match a different combination of language codes. For instance, in the case of en_US, the same URL is repeated three times with the following keys: en_us, en, and us.
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.
hook example usage:

In order to use this filter Browser language redirect must be enabled on the WPML -> Languages.

Following code can be used to redirect browser to homepage for a post when language is changed to specific one

function example_callback( $params ) {
	global $post;
	// Redirect the French language to the home page if the current page ID is 123
	if ( $post->ID === 123 ) {
		$params['pageLanguage'] = 'en';
		$params['languageUrls'] = [ 'fr' => 'http://example.com/fr/' ];
	}
	return $params;
}
add_filter( 'wpml_browser_redirect_language_params', 'example_callback' );