Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Taylor McCaslin

    (@taylor4484)

    Hi tooltester!

    Here’s a code snippet for you to try out, drop this into your functions.php file after you customize the redirects to your domains and respective countries. We’ve seen this work well with other GeoIP Users:

    function country_geo_redirect() {
    $country = getenv('HTTP_GEOIP_COUNTRY_CODE');
    if ( $country == "US" ) {
    wp_redirect( 'https://us.domain.com';, 301 );
    exit;
    } else if ( $country == "FR" ) {
    wp_redirect( 'https://fr.domain.com';, 301 );
    exit;
    }
    }
    add_action('init', country_geo_redirect');
    Thread Starter tooltester

    (@tooltester)

    Thank you, that’s great! Just one additional question. Would this script always bring the visitor back to the country specific page even if they selected English? For example, an English speaker in France wants to access the English page. Would there be a redirect loop then?

    Plugin Contributor Taylor McCaslin

    (@taylor4484)

    You are correct, this will always perform a redirect.

    There are ways that you could modify this function to allow overrides if a certain page parameter, however we do not recommend any specific solution here. This would be custom code you would write dependent on whatever multilingual solution you are using for “selecting english” even if not in an english speaking country.

    Do post what you end up doing here, we’re always looking to better understand how people are leveraging GeoIP with custom code.

    Thread Starter tooltester

    (@tooltester)

    Thank you, I will!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Setting up country specific redirects’ is closed to new replies.