Skip to content

Instantly share code, notes, and snippets.

@timersys
Last active September 29, 2015 12:04
Show Gist options
  • Select an option

  • Save timersys/df448a979fd88395df22 to your computer and use it in GitHub Desktop.

Select an option

Save timersys/df448a979fd88395df22 to your computer and use it in GitHub Desktop.
Redirect user by country or state to a different site
<?php
/*
* Redirect user by country or state to a different site
* using Geotargeting WordPress plugin . https://timersys.com/geotargeting
*/
// if some functions such as is_front_page are not working change hook to a later one like template_redirect
add_action( 'init', 'geot_redirect' );
function geot_redirect() {
if( ! function_exists( 'geot_target') )
return;
// if we are not in front page exit as we only want to redirect users that arrive to front page
if( ! is_front_page() )
return;
// you can use geot_target or geot_state Check full API in https://timersys.com/geotargeting/docs/functions-api/
if( geot_target( 'US' ) ) {
wp_redirect( 'http://Mysite.us');
die();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment