Skip to content

Instantly share code, notes, and snippets.

Last active September 23, 2021 16:39
What would you like to do?
Custom country widget for GeotargetingWP
* The following code serves as an example and could be copied over to your theme's functions.php file
* Ideally you want to separate your javascript files and load them separatly.
* This example it's based on the following HTML structure:
* <a href="#" data-iso="US" class="geot-countries">United States</a> - <a href="#" data-iso="AR" class="geot-countries">Argentina</a>
add_action('wp_footer', 'my_custom_geot_widget' );
function my_custom_geot_widget(){
jQuery(function ($) {
$(document).ready(function () {
$('.geot-countries').on( 'click', function(e) {
const iso = $(this).data('iso');
// cookie for the plugin and our regular dropdown widget
geotWP.createCookie('geot_country', iso, 999);
// if you use wprocket add this cookie to create different cache based on countries
// geotWP.createCookie('geot_rocket_country', iso, 999);
// if you are in pantheon hosting, you need to add this line
// geotWP.createCookie('STYXKEY_geot_country', iso, 999);
// select the option to apply your own css
// reload the page, so the change applies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment