Redirect Based on Location Example (Solved)
-
I would have posted this to solve someone else’s issue below but it was closed. My team needed this and I figured it would be nice to share.
<?php /** * Redirect international users from domestic to international website. */ function wpe_country_code_redirect() { // Verify that the WPEngine Geo IP plugin is available. if ( ! class_exists( '\WPEngine\GeoIp' ) ) { return; } // Domestic country code $domestic_country_code = 'US'; // URL to international version of website. $international_url = 'https://www.what_ever_site.international'; // Instantiate GeoIp class. $geo = WPEngine\GeoIp::instance(); // Get current country code. $user_country_code = $geo->country(); // If the current user is not accessing the website from the // domestic country code, then redirect to international version. if ( $domestic_country_code !== $user_country_code ) { wp_redirect( $international_url ); exit; } } add_action( 'init', 'wpe_country_code_redirect' );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Redirect Based on Location Example (Solved)’ is closed to new replies.