Country Filter WordPress plugin
Description
Country Filter plugins allows you to control the visibility of WordPress elements depending on the users country of origin. You can hide or show certain elements of a page or some sections of a post from users browsing from a particular country. For example you could have a ‘donate’ button that displays only if the user is browsing from France.
Developers and designers could use the plugin to load different stylesheets based on the users country. Services like hulu.com uses techniques such as this to constrain viewership to a particular country.
Supported WordPress versions
WordPress 2.5 and above. Tested upto version 3.3.
Purchase Plugin

The download link will be emailed to you immediately on payment. Also, any future updates will be free for all buyers and will be emailed to you as and when available.
Installing the Country Filter plugin
Installation instructions are provided in the download.
>> Usage
Short codes
You can show/hide content in posts by using the ‘country-filter‘ shortcode. For example if you want to show a certain part of your posts only to users who are browsing from ‘United States’ or from ‘India’ than you can use the following code.
[country-filter code="us, in" display="1"] Hello World! [/country-filter] |
This will display the string ‘Hello World!’ only for the users in US and India. People in other countries will not be able to see the string. On the other hand, setting the display attribute to ’0′ will hide the content for users in US and India but will display the string to people from other countries as given in the following code.
[country-filter code="us, in" display="0"] Hello World! [/country-filter] |
The short code takes two attributes, both of which are mandatory.
code : A comma separated list of country codes.
display : Set to ’1′ if you want to display or ’0′ if you want to hide the content. If set to ’0′ the content will be hidden for the given countries but displayed for others.
Filtering other content
You can also filter content other than posts with the ‘isCountryInFilter’ function. For example if you would like to display some content – like a button or some section of a web page, that should only be visible for people browsing from US, UK or Australia than you can do it as follows.
. . <?php if (function_exists('isCountryInFilter')) { ?> <?php if(isCountryInFilter(array("us", "gb", "au"))) { ?> // The content here is displayed only for users // browsing from US, UK or Australia. <?php } } ?> . . |
You can also add a ‘else’ section.
. . <?php if (function_exists('isCountryInFilter')) { ?> <?php if(isCountryInFilter(array("us", "gb", "au"))) { ?> // The content here is displayed only for users // browsing from US, UK or Australia. <?php } else { ?> // People from other countries will see the content // given here but not the above. <?php } } ?> . . |
Note that the ‘isCountryInFilter’ function takes an array of country codes and returns true if the country code of the user browsing the site is in the array.
Another function added in version 1.5 is showCountryContentInPage. This function is just like the short code version above, but can be used to manipulate content other than posts. This takes an extra ‘display’ parameter after the countries array. If set to ’1′ than the content will be only displayed for the given countries. If set to ’0′ than the content will be hidden for the given countries but displayed for others.
<?php if (function_exists('showCountryContentInPage')) { ?> <?php if(showCountryContentInPage(array("us", "gb", "au"), 1)) { ?> // The content here is displayed only for users // browsing from US, UK or Australia. <?php } } ?> |
Troubleshooting
Plugin fails to activate
If the plugin fails to activate and displays and error, check the table names in the database, they are case sensitive. They should be ‘ip2nation’ and ‘ip2nationCountries’ if you are using the ip2nation Version of the plugin. This will work on Windows but will fail on Linux systems as the files there are case sensitive.
Plugin gives inaccurate results
This can happen if your PC is behind a firewall, proxy or a VPN. This programs tend to hide your original IP address, which can result in incorrect results. This is something the plugin cannot do anything about.
FAQ’s
Will the plugin work with mobile devices and sites.
As long as your mobile device provides a correct ip address the plugin will work without any problem. Go to a site such as http://www.whatismyip.org/ or http://www.whatismyip.com/ to check the ip address of your mobile.
Purchase Plugin
Changelog:
# Version 1.01
* FIXED: Problem between spaces in country codes
# Version 1.1
* ADDED: Support for nested shortcodes
# Version 1.5
* ADDED: New function and changed some logic.
Thanks to Matt of NuFlux Media Inc for providing excellent feedback.
# Version 1.5.1
* ADDED: Check to confirm presence of ‘ip2nation’ database tables




68 Responses
1
WordPress Plugin Releases for 07/08 | Weblog Tools Collection
July 7th, 2009 at 1:08 pm
[...] Country Filter [...]
2
EasySeo | WordPress Plugin Releases for 07/08 | SEO2Blog
July 7th, 2009 at 5:41 pm
[...] Country Filter [...]
3
New Wordpress Plugins Release 07/08/2009
July 7th, 2009 at 6:08 pm
[...] Country Filter [...]
4
WordPress Plugin Releases for 07/08 | The Cliffmaster
July 8th, 2009 at 6:39 am
[...] Country Filter [...]
5
Tim Marchant
July 12th, 2009 at 2:14 am
Thanks for this. It would be worth adding a couple of lines above telling people how to do:
} else {
6
Matt
July 17th, 2009 at 11:55 am
Hey Sameer,
Thanks for the plugin! It’s exactly what I have been looking for.
But unfortunately, it’s not working for me. I have the plugin activated, and the database installed (I see them in phpmyadmin).
I tried the following code,
[country-filter code="us, in, uk" display="1"]
Hello World!
[/country-filter]
and
[country-filter code="us, in, uk" display="0"]
Hello World!
[/country-filter]
But I see nothing at all in my post. Any ideas?
Many thanks,
Matt
7
Matt
July 17th, 2009 at 12:01 pm
Damn, the php code in my sidebar didn’t work either :/
I’m quite sure I set everything up okay.
Thanks for your help, it should be a great plugin!
8
WordPress Plugin Releases for 07/08 « Web And Graphics Design Tutorials
July 28th, 2009 at 8:56 am
[...] Country Filter [...]
9
New Useful WordPress Tricks & Hacks | ART HACKER
August 13th, 2009 at 10:48 pm
[...] Filter content by country [...]
10
30+ Tips&Plugin per Wordpress | GeekTwice
August 20th, 2009 at 1:05 am
[...] Filter Content By Country [...]
11
Unlimited New Useful Wordpress Tips,Tricks & Hacks - Themeflash : One Stop For All Your Web Resources
August 23rd, 2009 at 11:41 pm
[...] Filter content by country [...]
12
30+ New Useful WordPress Tricks & Hacks | MEN blog . net
September 4th, 2009 at 2:26 am
[...] Filter content by country [...]
13
Sergio Hernandez
September 5th, 2009 at 7:42 am
Thanks, Great plugin…! The best..
14
30+ New Useful WordPress Tricks & Hacks | My Tech way
September 14th, 2009 at 6:51 am
[...] Filter content by country [...]
15
John Thornley
October 1st, 2009 at 4:38 am
If you are from the UK (like me) then just be aware that the example is incorrect. You need to use “gb” not “uk” as is stated in the example.
Just trying this plugin out and it wasn’t working… when I investigated then this was the problem.
Apart from that, it seems like a brilliant plugin. Thank you very much for all your hard work in making it.
Cheers
John
http://www.friendsatrest.com
16
sakthi Ganesh
October 2nd, 2009 at 9:56 am
I really appreciate for these kind of exceptional plug-in . Hats off for the good work . Looking more in future
17
George Rakkos
October 13th, 2009 at 4:53 am
I second this:
“Thanks for this. It would be worth adding a couple of lines above telling people how to do:
} else {“
18
George Rakkos
October 13th, 2009 at 5:01 am
small problem i updated to 1.5 and it does not work as before
19
Leannekera
November 12th, 2009 at 7:47 am
This plugin saved my life, I really cant thank you enough!
We originally quoted for a site to be duplicated 7 times for 7 different country prices. Now all we need to do is 1 wordpress build and utilize this script to enable the site to hide/show the different prices based on ip.
I LOVE YOU FOR THIS SCRIPT!
20
Sakthi Ganesh
November 23rd, 2009 at 7:52 am
I have found some issues with my setup ( may be with this plugin)
I have blacklisted the various offensive words using the filter textbox . one of the word is “ass” .I have included the conclusion that ,the plugin may find and replace the ” Three letter world” combination of “a”,”S”,”S” that forms the word “ass”.
But what it happened is
It blocked the words that start with particular three letter word .For example it blocked and replaced theword
“Assets” with ” ***ets ” which one i didn’t expected
For example the line is become
To protect the digital ***ets( which one is gone meaningless )
Is that any solution for that ?
sameer
November 23rd, 2009 at 10:12 pm
The plugin doesn’t work as a language filter, but as a content filter for country codes.
22
Timo
November 24th, 2009 at 12:13 am
It seems that this plugin doesn’t work inside a widget
I want to create a text box widget and insert country filter code there (to show some banners to specific country) but it just shows the country filter code there. Anyone else has the same issue?
23
Sakthi Ganesh
November 24th, 2009 at 1:12 am
Hi:
I am very sorry for mis posted comment numbered 20.
The comment numbered 20 is mis posted and these bug report should be made to the plugin
http://wordpress.org/extend/plugins/wp-content-filter/
Sammer your plugin is a exceptional plugin i will write a review on my blog and i will let you know!
I am sorry sameer and the fellow readers for this .
Thanks
24
ShocWave
December 1st, 2009 at 1:48 pm
You know what would be really cool? If it was possible to show or hide an entire post, not just its contents.
Maybe it can be done through tags or catagories?
25
Simone Carletti
December 22nd, 2009 at 10:05 pm
Hello,
there’s a small bug when the user is connecting through a proxy.
You should change
$ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"])));
to
$ip_address = trim(end(split(“,”, $_SERVER["HTTP_X_FORWARDED_FOR"])));
Proxies usually appends the full ip chain in the header, values are separated by commas. The last element is the public IP.
Example
78.78.78.78 # public IP
192.168.1.1, 78.78.78.78 # proxy + public IP
192.168.1.140, 192.168.1.1, 78.78.78.78 # lan + proxy + public IP
26
James
December 28th, 2009 at 7:55 pm
Huge Thanks!
If I am able to implement this the way that I am planning (geo-specific advertising) it should bring me some extra income and if it does then I will definitely float some of that your way!
By the way, the final example above is using the wrong function. It should be the “showCountryContentInPage” in the example, correct?
sameer
December 28th, 2009 at 10:26 pm
Thanks for pointing out the error James.
28
James
December 29th, 2009 at 10:33 pm
I am very curious about Simone Carletti’s suggestion above regarding some additional parsing to handle proxied IP addresses.
Have you tested this Simone?
Sameer, what do you think?
I can tell you that I tried using my company’s VPN in a different country and the filter responded to the country of my VPN connection (not my true location), just as most web site’s do. Would Simone’s suggestion allow this code to see my originating IP address when using a VPN connection?
sameer
December 29th, 2009 at 11:52 pm
Hello James! I’ve not yet tested the proxy modification at my end, will do in a couple of days; meanwhile you can try it at your end and let me know the results.
30
plienine
January 5th, 2010 at 12:54 pm
Hello,
Is it possible to use this plugin in e107 CMS ???
Great plugin and I want to integrate it in e107 system…
Thank You for any kind of help….
sameer
January 5th, 2010 at 9:00 pm
You cannot use the plugin in e107.
32
Veerendra
March 12th, 2010 at 10:21 am
Hi sameer
great plugin to filter content. I was searching this kind of filtering plugin for doing some css tricks in my website.So I can add some custom css elements or change look of some divs based on visitors country. any idea to do this ?
btw
I am a designer and frontend developer for static website to cms. I also provide design services. I live in pune. Someday we can meet up for coffee.
bhetu ya ekda !
sameer
March 12th, 2010 at 10:38 pm
You can try this in your templates header.php :
http://pastie.org/867569
34
Alex
April 8th, 2010 at 1:34 am
Sameer,
Great plugin! I’ve been searching for something like this. I want to test this out with different ips via proxies. Did you get a chance to make modifications to the plugin to accommodate proxies as suggested in above post?
sameer
April 8th, 2010 at 8:11 pm
Alex!
I’ve not yet accommodated for proxies yet!
36
Alex
April 8th, 2010 at 10:17 pm
Thanks Sameer.
Is there any way to test the dynamic content that shows up based on country? I’m sure the plugin works great, but how would I test the country-specific message or in my case a flash file without actually seeing it?
Can anyone else comment on how they were able to test their country-specific content?
sameer
April 8th, 2010 at 11:14 pm
Alex!
You need to run your site through some proxy servers. Try this one. but with caution:
http://rosinstrument.com/cgi-proxy.htm
It lets you select the Country where the proxy is located. This way you can check if your data is correctly showing up for that particular country. Also check this link addressing your type of query:
http://www.ehow.com/how_5458081_view-streaming-online-television-proxy-server.html
38
John
May 7th, 2010 at 12:51 pm
Hi Sameer,
Thanks for creating this plugin, it should be really useful for creating targeted advertising content.
I am experiencing a slight inconsistency where my content, which is targeted at the UK, appears on my home machine but not on my work machine. I’ve checked both IP addresses here: http://whatismyipaddress.com/ip-lookup and they are both geo-located as uk. Do you have any ideas of why the content does not appear?
sameer
May 9th, 2010 at 9:55 pm
Check if the ip is behind a firewall.
40
John
May 10th, 2010 at 1:06 am
Hi Sameer,
Seems to be working ok now. Must have been a problem at my end.
All the best,
John
41
Simo
June 19th, 2010 at 5:39 am
Hi Samir,
great plugin, thank you. It worked perfect for me until today (when I installed WP 3.0).
The thing that I want to appear only for some countries is a table built with Wp-Table Reloaded plugin. When I installed WP 3.0 the table stopped appearing at all for any country.
Can you give me a clue what to do.
Thanks.
sameer
June 19th, 2010 at 6:51 am
The plugin requires the ip2nation database, if your WordPress installation is new check if the database is present.
table 1 : ip2nation
table 2 : ip2nationcountries
43
Simo
June 19th, 2010 at 8:44 am
Hi Sameer,
please disregard my previous comment. I tested further the problem is only with Mozilla browser. I guess that there is something wrong at my end.
Thanks again for the great plugin.
44
Italo
August 25th, 2011 at 5:48 am
Hi Sameer
I need filter content by country, and this plugin is perfect. But I need add a button o category filter, for make more simple use… I can make this?
Thanks
45
Italo
August 25th, 2011 at 9:51 am
My friend: this plugin hide part of post, but I need hide or show entire posts…
sameer
August 25th, 2011 at 8:18 pm
Italo, the plugin currently does not support hiding entire posts and at present have no plans on doing the same. But when I update the plugin I’ll surely let you know.
Thanks!
47
gaYan
September 6th, 2011 at 3:34 am
What about “else”
It would be better if we can use the tag ‘else”
sameer
September 6th, 2011 at 4:57 am
Of course you are free to use the ‘else’ keyword when the ‘if’ condition is not satisfied.
49
coman
September 8th, 2011 at 3:21 am
Got this error:
The plugin requires the ‘ip2nation’ and ‘ip2nationcountries’ database to be installed.
You can download the same from http://www.ip2nation.com
But i imported the tables in my database. It seems like the plugin can’t find them.
Is there a fix for this?
THanks!
50
gaYan
September 9th, 2011 at 8:50 pm
I have already installed Country Filter Free version and it seems not working now.
sameer
September 9th, 2011 at 10:44 pm
The free version has been removed. The files posted at wordpress repository are blank, as it does not allow deletion of existing files.
52
Paul
September 14th, 2011 at 4:53 am
Just so I have the understanding of GPL licensing correct.
I am running 1.5.0 of the plugin as downloaded from WordPress.org
Is this permitted? If I understand GPL License agreements, there no reason I shouldn’t be allowed to use it with all rights reserved?
sameer
September 14th, 2011 at 5:12 am
yes, you can use it.
54
Dee
October 4th, 2011 at 1:15 am
Thinking of buying this plugin.
Will it work for mobile sites where I want to show different things depending for different countries?
sameer
October 4th, 2011 at 6:57 am
Yes it works with mobile devices. As long as your mobile provides a correct ip address, the plugin will work correctly.
56
Dee
October 4th, 2011 at 2:39 pm
Hi again,
Just purchased your plugin. Installed successfully but when I come to activate, I get this error message “The plugin does not have a valid header.”.
Help.
I have also downloaded the ip2nation files mentioned above. No idea where to store it, so I just kept the ip2nation zip file in the same folder as the Country-Filter zip file
57
Dee
October 4th, 2011 at 2:49 pm
Please ignore my last question. I know what I’ve done wrong.
58
Erik
November 6th, 2011 at 2:00 pm
Is there a list of country codes to use with this plugin? Could not find them at ip2nation.
Also wondering how to install the ip2nation files before ordering .. thanks
59
Candie
November 15th, 2011 at 8:15 am
Hi, I’m using Ad Injection wordpress plugin and saw that the author recommended your plugin if I we want to filter ads.
I’d like to buy your plugin but I’m not sure if this will work with WP Super Cache as well. Will I still have dynamic ad contents and at the same time filter them by your plugin?
Looking forward to your response! Thanks!
sameer
November 15th, 2011 at 9:25 am
The plugin currently does not support super cache.
61
Donald Laurel
December 22nd, 2011 at 7:19 am
Is their a way to show/hide the website from specific country? If there is, what is the code and where to put using wordpress version 3.2.1.
all I can see here is show/hide some elements in pages and posts.
Hoping for your quickest reply.
Thank you
sameer
December 22nd, 2011 at 10:15 am
You cannot use the plugin to hide whole sites. There is another plugin, ‘Country Redirect’ that allows you to redirect particular pages or the home page to other pages or urls.
63
Donald Laurel
December 22nd, 2011 at 11:03 pm
Hi Sameer,
I see. Thank you for the quick responds.
Donald
64
Youssef
December 23rd, 2011 at 10:27 am
Works great with WordPress 3.3 ! Thanks a lot!
65
Carrie
December 23rd, 2011 at 12:23 pm
Not sure what’s wrong, but I’ve set different ad for UK readers and US readers, but somehow, the plugin keeps displaying the US ads even though I’ve used UK proxy to view my web. I’m using maxmind version.
Please help Sameer
sameer
December 23rd, 2011 at 8:19 pm
Hello Carrie!
There are three reasons.
1. Check that no cache plugin like ‘wp-super cache’ is installed.
2. Go to ‘http://www.whatismyip.com/‘ and get the ip of your proxy server. Then go to ‘http://www.maxmind.com/‘ and at the left bottom corner on the page enter the ip address. See what location it is returning.
3. Update your ‘GeoIP.dat’ file in the plugin directory with the latest version of the file from:
http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
Tell me how it goes.
67
Youssef
January 4th, 2012 at 2:26 am
Okay so i’m using GeoIP Lite and getting some complaints that the content doesn’t show.. everything works fine but some IP adresses are obviously not in the GeoIP database.. i was wondering if ip2nation is maybe better then GeoIP ?
Somebody who tried both and know what the best one is?
Thanks
sameer
January 4th, 2012 at 2:36 am
Hello Youssef.
Did you update the GeoIP lite database from their website : http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
Also if some ips are behind a firewall or a proxy, then they will not work correctly. Their is no solution for that.