Created
November 9, 2015 12:50
-
-
Save timersys/2e87406162b8ccb56c8c to your computer and use it in GitHub Desktop.
Redirect users to same site depending on language of polylang
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 same site using WPML | |
| * using Geotargeting WordPress plugin . https://timersys.com/geotargeting | |
| */ | |
| function geot_redirects() { | |
| // grab wpml language of current user | |
| $lang = pll_current_language('slug'); | |
| // grab country code of current user | |
| $user_code = geot_country_code(); | |
| // if you want to debug insert ?geot_debug=true to your url | |
| if( isset( $_GET['geot_debug'] ) ) { | |
| var_dump( $lang ); | |
| var_dump( $user_code ); | |
| die(); | |
| } | |
| if($user_code == "UK" && $lang != "gb"){ | |
| wp_safe_redirect("https://yourwebsite/gb/");die(); | |
| } | |
| if($user_code == "US" && $lang != "en"){ | |
| wp_safe_redirect("https://yourwebsite/en/");die(); | |
| } | |
| if($user_code == "FR" && $lang != "fr"){ | |
| wp_safe_redirect("https://yourwebsite/fr/");die(); | |
| } | |
| if($user_code == "DE" && $lang != "de"){ | |
| wp_safe_redirect("https://yourwebsite/de/");die(); | |
| } | |
| if($user_code == "ES" && $lang != "es"){ | |
| wp_safe_redirect("https://yourwebsite/es/");die(); | |
| } | |
| } | |
| add_action( 'init', 'geot_redirects'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment