Created
May 26, 2021 14:54
-
-
Save timersys/1a876975a470082e7ccc3c01415de0e6 to your computer and use it in GitHub Desktop.
Changing location in GeotargetingWP using URL parameters or querys tring
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 | |
/** | |
* Allow users to change location with query string like this | |
* https://yourdomain.com?geot_country=US | |
**/ | |
add_action( 'init', 'change_geolocation_with_url' ); | |
function change_geolocation_with_url(){ | |
if( ! isset( $_GET['geot_country'] ) ) { | |
return; | |
} | |
$iso = strtoupper( esc_attr( $_GET['geot_country'] ) ); | |
// update wprocket country cookie | |
setcookie( 'geot_rocket_country', $iso, 0, '/' ); | |
// update cookie for dropdown widget | |
setcookie( 'geot_country', $iso, 0, '/' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment