Geo Targeted Caching plugin for WP Super Cache

Geo Targeted Caching is a plugin for WP Super Cache that makes it so that each page is cached on a per country basis. This can be useful if pages on your website contain content that differs based on the location of a visitor.

Download version 2015-03-27

The plugin requires that your web server has GeoIP functionality available or the PHP GeoIP extension is installed.

For an explanation of why caching can be problematic with dynamic content, and how Geo targeted page caching / cache page key modification (used by this plugin) compares to other methods, please see this page: Differences between caching methods with Geo targeted content.

To use the plugin, first extract the contents of the zip file into your Super Cache Plugins folder. You should not be using the Super Cache Plugins folder in its default location, see here for how to change it: Moving the WP Super Cache Plugins folder.

In your WordPress admin panel, go to the WP Super Cache settings page. Go to the advanced tab. Under the Caching section, choose Use PHP to serve cache files.

Save the settings and go to the Plugins tab of the WP Super Cache Settings. Scroll down to find the entry Geo Targeted Caching. Check the enabled option then press the update button.

Plugin settings on the WP Super Cache Settings plugins page

After doing this, you may want to clear the cache to remove all old copies of cached files that have been cached on a worldwide basis rather than per country. This is not necessary, but just removes the old cached files no longer needed.

If you find anything with the plugin isn’t working, or any of the above isn’t clear, please let me know (leave a comment below or send me a message).

Posted on by xoogu, last updated

7 Responses to “Geo Targeted Caching plugin for WP Super Cache”

  1. Daniel says:

    How does one ensure the web server (nginx in my case) has GeoIP functionality available or the PHP GeoIP extension is installed?

    How do you determine if a web server has GeoIP functionality available?

    • xoogu says:

      If you are able to view a phpinfo() page on your server, that should give you the correct information. It lists the enabled extensions (so you can check if the PHP GeoIP extension is listed or not). If the server (Apache / Nginx etc) is built with GeoIP support, then on the phpinfo() page under the SERVER variables section, you should see $_SERVER[‘GEOIP_COUNTRY_CODE’] listed.

      Or just install the extension and see if it has server and php geoip extension options selectable or not. (It should only list the geoIP lookup methods that are available).

  2. Daniel says:

    I (accidentally) found out that besides extracting the contents of the zip file into your Super Cache Plugins folder, it is also possible to upload the zip file (as-is) as a WordPress plugin in the WP-Admin panel. Is there any specific reason to not do it this way? (It seems to work just as well)

    • xoogu says:

      I think I’ll have to try that out, as I don’t understand how it would work, unless you have late init enabled. My understanding is that without late init, no standard plugins should be loaded (but WPSC does load its plugins). So the geo-cache plugin shouldn’t get loaded if installed as a normal plugin, other than when initially generating the page to cache.

      But given that it works for you, my understanding may be wrong (or I’m missing something). So I’ll need to test it out myself and see what’s happening there.

      Dave

      • xoogu says:

        I’ve tested this now, and it doesn’t work if you just use the default PHP caching method of WP Super Cache. The plugin will be loaded at the time the page is initially cached, and so create the geo-cached page. But the plugin won’t be loaded when WP Super Cache checks if the cached page exists (as standard WP plugins are not loaded that early). So it will just check for a standard cached page, not the geo-cached page. It will see the standard cached page does not exist, then proceed to load WP fully, create the page, and geo-cache it.

        So using this plugin as a standard WP plugin will effectively disable WP Super Cache as the cached pages will never be loaded.

        If you’re using the web server to serve cached pages created by WP Super Cache, and have the appropriate rules in place to make it look for the correct geo-cached page, then everything should work fine. Because you’re using the server to look for and serve the cached pages in this case, it doesn’t matter that the plugin isn’t loaded early, only that it is loaded in time for generating the cached page (which it will be) when none exists.

        Dave

  3. John says:

    The plugin works good.

    However is there a way to make it so that it keeps a cached version for all countries except X and then for X it keeps a different version.

    Right now it’s for all countries individually but would be awesome if we could select country X, Y etc. and then all others except X,Y, etc. to have the same.

    I see you have this for W3 Total Cache. Is it possible for WP Super Cache too?

    • xoogu says:

      Hi John

      Thanks for the suggestion, I will try and add that in a future version. I’m afraid it might be a while yet though as I’m really busy at the moment.

      Cheers

      Dave

Leave a Reply to Daniel