Skip to content

Instantly share code, notes, and snippets.

@atwellpub
Created January 25, 2015 20:30
Show Gist options
  • Select an option

  • Save atwellpub/d21afad57c8bdc03ce10 to your computer and use it in GitHub Desktop.

Select an option

Save atwellpub/d21afad57c8bdc03ce10 to your computer and use it in GitHub Desktop.
Sets the country dropdown fields to visitors IP's country
<?php
/**
* Adds geotargeting js capabilities to javascript
*/
add_action( 'wp_enqueue_scripts' , 'inbound_add_geotargeting_js' );
function inbound_add_geotargeting_js () {
wp_enqueue_script( 'geoplugin' , 'http://www.geoplugin.net/javascript.gp');
}
add_action( 'wp_footer' , 'inbound_set_correct_country' );
function inbound_set_correct_country () {
?>
<script type='text/javascript'>
jQuery( document ).ready( function() {
jQuery( "select[name='wpleads_country_code']" ).val(geoplugin_countryCode());
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment