Skip to content

Instantly share code, notes, and snippets.

@timersys
Created May 26, 2021 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save timersys/1a876975a470082e7ccc3c01415de0e6 to your computer and use it in GitHub Desktop.
Save timersys/1a876975a470082e7ccc3c01415de0e6 to your computer and use it in GitHub Desktop.
Changing location in GeotargetingWP using URL parameters or querys tring
<?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