wpml_browser_redirect_language_params
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.
Arguments
pageLanguageStores the current language code.languageUrlsStores 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 ofen_US, the same URL is repeated three times with the following keys:en_us,en, andus.cookieStores an associative array with the cookie settings. Please refer to Document.cookie (opens in a new tab) for more details. The keys are:namethe name of the cookie (defaults to_icl_visitor_lang_js).domainthe domain in which the cookie must be used (defaults to the current domain and is not meant to be changed).paththe path of the cookie (defaults to/).expirationthe number of hours the cookie lasts. From WPML 5.3, it is the number set in the Visitor language section of WPMLSettingsURLs and SEO (Redirect each visitor at most once every … hours or After a visitor closes the bar, hide it for … hours). The minimum is 24. In WPML 5.2 and older, it is the number in Remember visitors’ language preference, in the Browser language redirect section of WPMLSettingsLanguages.
From WPML 5.3, the array also has these keys:
firstVisitModeredirectwhen the automatic redirect is on,barwhen the language bar is on, andkeepwhen neither is.allLanguagesAn ordered list of{ code, url, missing }entries, one per language in the language switcher.urlis this page in that language. When the translation is missing,urlis the home page of that language andmissingis true.siteOriginsThe origins (scheme://host[:port]) of everyallLanguagesURL and of the home page of every active language. A visitor who comes from one of them is already on the site.isSearchWhether the current page is a search results page.chosenLanguageAn associative array about the language a visitor picks in a language switcher:enabled(whether WPML keeps that language and shows it on the next visit, see wpml_redirect_to_chosen_language),languages(the codes of all active languages) andcookie(thename,domain,pathandmaxAgein seconds of the cookie that keeps the picked language).barOnly whenfirstVisitModeisbar: the texts of the language bar in each active language (texts), the text direction of each language (dir) and its language tag (tags).
Example Usage
From WPML 5.3, WPML runs this filter when at least one option in the Visitor language section of WPMLSettingsURLs and SEO is on: showing returning visitors the language they picked, the language bar or the automatic redirect. In WPML 5.2 and older, it runs only when Browser language redirect is on in WPMLSettingsLanguages.
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' );