• Situation is SiteA (main used URL) is on WordPress platform (English) and SiteB is on another URL and platform (German, Italian).
    I’m searching for a Function or Plugin who allows me on SiteA to redirect browser language DE and IT once per user session to SiteB. Perfect would be the option to additionally redirected also IP Address locations in DE, AT, IT but I think Geo-IP is rather complicated.
    I could only find an expensive WP-Plugin doing Geo-IP redirection our outdated WP-Plugins not offering the one time redirect. Also no interesting script was a search result.
    I would be happy if some WP-PHP script for the theme functions.php could do this, but personally I’m not able to code from scratch.

    • This topic was modified 4 years, 8 months ago by ChrisFo.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    This code added to functions.php will redirect based on the Accept-Language header value sent by the browser. This should represent the user’s language preferences they’ve set in their browser.

    add_action('init', function() {
    	$langs = apache_request_headers()['Accept-Language'];
    	if ( false !== strpos( $langs, 'de' /*language code*/)) {
    		wp_redirect('https://example.com/de/', 302);
    		exit;
    	}
    	if ( false !== strpos( $langs, 'it' /*language code*/)) {
    		wp_redirect('https://example.com/it/', 302);
    		exit;
    	}
    });

    This has nothing to do with user sessions. This solution is rather rude in that it redirects with no option to do otherwise other than altering one’s browser settings. A better solution IMO would be to redirect based on a cookie or session value indicating user language preference for this specific site. That’s more involved and not something I’m able to offer here. I’d expect there to be plugins that offer such functionality, though I don’t personally know of one.

Viewing 1 replies (of 1 total)
  • The topic ‘Searching: Language Redirection one time to another site’ is closed to new replies.