Install & Setup
WP-Geolocation-JS Download, Installation, Upgrade and Setup Instructions
Overview
The WP-Geolocation-JS plugin is a WordPress plugin that uses your visitor’s IP address to display their geographical information anywhere in your WordPress theme.
Using the MaxMind free JavaScript geolocation service, the plugin can display a visitor’s country, city, state/province, longitude and latitude using WordPress shortcodes.
Download WP-Geolocation-JS (2674)
Installation Instructions
- Extract the downloaded plugin to /wp-content/plugins/
- Activate the plugin from the WordPress plugin admin page
Usage Instructions
- Within any blog post or page, you can use the following shortcodes:
[mmjs-countrycode] - the ISO 3166-2 country code [mmjs-countryname] - the country name [mmjs-city] - the city name [mmjs-region] - the ISO 3166-2 country code (state or province abreviation) [mmjs-regionname] - the region name [mmjs-lat] - latitude [mmjs-long] - longitude [mmjs-postalcode] - post/zip code [mmjs-ip] - ip address
- The plugin also generates corresponding JavaScript variables in your theme for use with JQuery, dynamic forms, etc:
mmjsCountryCode mmjsCountryName mmjsCity mmjsRegion mmjsRegionName mmjsLat mmjsLong mmjsPostalCode mmjsIPAddress
Troubleshooting
The correct city doesn’t get displayed!
The city is based on the IP address so it can be wrong for several reasons. If you live in a small town, a nearby larger city may be displayed. if your ISP is in another city, that city may be displayed. If you’re on a proxy server, the IP of the proxy server will be used, so the location of the proxy will be displayed.
The same city is always displayed!
This is often the result of a cached page (i.e. using wp-cache). Please turn off caching for the pages you wish to use this plugin on. There should be a field under the caching plugin options to add pages to exclude.
Is anything saved in my MySQL database? Can I keep track of visitor locations?
In short, no. This plugin is focused on being lightweight and fast. You may wish to look at other plugins with more features like Firestats or Geoplugin.
Is there anything to update or download?
Nope! WP-Geolocation-JS uses calls to MaxMind’s free JavaSciprt geolocation service, so it’s fast, lightweight, and free!
Do you take donations? How can I thank you?
Well, if you’re gonna twist my arm, I guess I could accept a cup of coffee. Thanks!











How can i use this plugin in contact form 7 ? I want also the location of user who has tried to contact. How can i do this?? Please give me reply as soon as possible
You’d want to use JavaScript to set the values of city or country when the form loads. that code would be placed after the Contact Form 7 code in the form editor. For instance, if you had a city field: [text your-city] (Contact Form 7 markup), then you might h ave some code like this:
<script language="javascript">userRegion = document.getElementById('your-city');
if(userRegion){
userRegion.value = mmjsRegionName;
}
</script>
Now, this code is pretty simple because it doesn’t assume that JQuery is installed in your theme. Hope that helps!
Hi Pat,
Thanks for your reply. Thanks a lot.
But one more thing. in the contact form i am not having any field like city , state etc. But in the mail form editor,i have written “[wpcf7.remote_ip]” to get the ip address in mail whwn anyone posts the form. and it is working. So i want to get the location from the IP address. Can you please help what should i need to do now??
Please do the needful.
This code should work to populate the IP address in your form. Let me know how it goes!
<script language="javascript">userIP = document.getElementById('wpcf7.remote_ip');
if(userIP){
userIP.value = mmjsIPAddress;
}
</script>
Deval, I think you’ve given me an idea for a tutorial – how to integrate the plugin values with forms!
and I am getting the field values like this in mail.
**snip**
I want all the location info in mail.Please let me know if there is any way. I am also trying for this and please you also do the needful.
Sorry about the problems with the code. Can you contact me directly? I’ll help debug from there. My email is pfriedl-at-nebulus-dot-org
Great plugin – I’m using it to show the uk phone number (in an image) to my uk visitors like this:
if(mmjsCountryCode == “GB”){
// display the UK Phone Number Image
document.write(”);
} else {
// display a default (US) Phone Number Image
document.write(”);
}
Great plugin, just what I was looking for. Now if I could just get what I am trying to do to work. Perhaps you can help?
I am trying to query by city, which I am getting from this plugin, and checking it against the a custom meta value for city that my posts have.
In short it should work something like this:
$geocity = do_shortcode(‘[mmjs-city]‘);
query_posts(“meta_key=city&meta_value=$geocity&post_type=listings”);
But this doesn’t work. I know the short code is working, I can echo that out separately so that’s not the issue. I also know my query posts is working because just to test I manually set $geocity = to my city (the exact same as it displays when I echo out the shortcode for the plugin) and it works just fine.
So the issue, I think atleast, is that the query doesn’t accept a value that outputs from a shortcode?
Is there a way to get this to work? Should I try using the javascript? If so, how?
I would really appreciate any help anyone has to offer. Thank you!
Miek,
Sorry for the delay in getting back to you – I’ve been a busy little monkey these last couple of weeks.
The reason the shortcode isn’t working is because it does rely on the javascript being included in the
of the page. So the shortcode won’t have a value until the page is fully rendered.I’m currently working on the server side version of the plugin that’ll be pure php, and I hope to have some movement on that sometime in the next couple months.
Hi all,
Great plugin & great database. This is working fine for me! Except, I’m having trouble using the shortcodes in the sidebar. They show up as cleartext, i.e. [mmjs-city] is shown to my visitors. Is there any way to avoid this?
If you’re using the basic WordPress text widget, then that may be the problem. I’d suggest using Advanced Text Widget – it can parse shortcodes and php, so it’s much more robust than the default widget.
Hope that helps!
Any thoughts on how to use this information in a widget on the sidebar?
Right now, the plugin uses javascript for grabbing the geolocation info. I’m working on making the plugin work on the server side of things so that you can hide/show content based on location, and that will let you use shortcodes as well for the geolocation info.
Right now though, you can check this example: http://www.wp-geolocation.com/comment-page-1#comment-11
Anything for php?
Thanks!
We are working on it – day job projects, while they keep the lights on, are unfortunately keeping me from producing a really sweet php version
I’m actually working on cloning myself so I can get more of these plugins done!
That’s awesome! thanks. God bless you man!