Last active
September 23, 2021 16:39
-
-
Save timersys/3a3d74bf42fb4fade6afc194605b7210 to your computer and use it in GitHub Desktop.
Custom country widget for GeotargetingWP
This file contains 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 | |
/* | |
* 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(){ | |
?> | |
<script> | |
jQuery(function ($) { | |
$(document).ready(function () { | |
$('.geot-countries').on( 'click', function(e) { | |
e.preventDefault(); | |
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 | |
$('.geot-countries').removeClass('selected'); | |
$(this).addClass('selected'); | |
// reload the page, so the change applies | |
window.location.reload(); | |
}); | |
}); | |
}); | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment