availability:

WPML Version: Coming soon!

description:

This filter is used when the theme developer wants to use a custom JavaScript for handling the browser redirection.

This filters a boolean set to true by default.
If the filter returns false, the JavaScript which takes care of redirecting the visitor won’t be enqueued.
The filter is applied only if the wpml_browser_redirect_language_params filter returns a valid $param (pageLanguage and languageUrls must be set).

type:
filter
category:
Site-Wide Language Information
parameters:

pageLanguage – defines a language for the page

languageUrls – an array that contains pairs of languages and URLs to which browser should be redirected

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 = array(
            'pageLanguage' => 'en',
            'languageUrls' => array( 'fr' => 'http://example.com/fr/' )
        );
    }

    return $params;
}

add_filter( 'wpml_browser_redirect_language_params', 'example_callback' );