Last active
September 29, 2015 12:04
-
-
Save timersys/df448a979fd88395df22 to your computer and use it in GitHub Desktop.
Redirect user by country or state to a different site
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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