JavaScript Integration

JavaScript is one of the most important scripts when it comes to WordPress. We thought about that and offered several objects through which you can access to geo information.

Within the first line of the HTML element, we have placed special objects through which you can access to geo information:

  • window.wp.geo – Using standard WordPress JavaScript wp object
  • window.cfgeo – Using direct window object
  • cf.geoplugin – Using old Geo Controller cf object (included conflict fix from the version 6.x.x).

All of this objects are the same and return geo information like this:

	url: "",
	host: "",
	protocol: "https",
	ip: "",
	ip_version: "4",
	ip_dns: "",
	ip_dns_host: "",
	ip_dns_provider: "",
	ip_number: "3649749028",
	country_code: "GB",
	country: "Great Britain",
	region: "England",
	region_code: "",
	city: "United Kingdom",
	continent: "Europe",
	continent_code: "EU",
	address: "United Kingdom, England, Great Britain",
	area_code: "",
	dma_code: "",
	latitude: "51.508529663086",
	longitude: "-0.12574000656605",
	timezone: "Europe/Zurich",
	locale: "en_GB,ga_GB,cy_GB,gd_GB,kw_GB",
	currency: "GBP",
	currency_symbol: "£",
	base_currency: "USD",
	base_currency_symbol: "$",
	currency_converter: "0.7684",
	ip_host: "",
	timestamp: "1580845604",
	timestamp_readable: "Tue, 04 Feb 2020 19:46:52 +0000",
	current_time: "20:10:57",
	current_date: "February 4, 2020",
	version: "7.8.8",
	is_vat: "1",
	in_eu: "1",
	gps: "0",
	accuracy_radius: "200km",
	lookup: "unlimited",
	credit: "These geographic information provides <a href="" target="_blank">Geo Controller</a>",
	flag: "",

Basic usage

When you have this informations, you can easy use it in your code. Here is the example:

	var city =,
        state	= geo.state,
        country =,
        ip  = geo.ip;
}(window.wp.geo || window.cfgeo || cf.geoplugin));

Also you can use it in the jQuery or Zepto:



}(jQuery || window.jQuery || Zepto || window.Zepto));


If you have problem with the cache, we provide AJAX action what you can use to get geo information from the plugin.

		method : 'POST',
		data: {
			'cfgeo_nonce' : nonce
		cache : false,
		async : false,
		url: ajaxurl + '?action=cfgeo_cache',
	}).done( function( data ) {
		console.log( data );  
}(jQuery || window.jQuery || Zepto || window.Zepto));

You need to generate nonce via PHP and provide to AJAX:


You can do with hidden input, data attribute, inline coding, wp_localize_script() or some 3rd way.

If this nonce missing you will not be able to get geo informations.

Was this page helpful?