Wordpress Geo-Targeting Instruction Manual

Page 1

Geo-Targeting Script Installation Instructions For Wordpress Show Unique Content Based On The Country Your Blog Visitor Is Browsing From!

If you currently do not have the Geo-Targeting Script, please visit: http://keithjameslock.com/wordpress-geo-targeting-script to obtain a copy. Note: This script requires that your server has php5 installed (most do) in order to run. There are instructions here (at the end of this manual) to quickly self-upgrade to php5 if you are hosted with GoDaddy.

Disclaimer: The Geo-Targeting Script is provided as-is. Although the script has been tested and is working perfectly for us, we cannot be responsible for your voluntary use of this script. You are responsible for the outcome of using it. Please be sure you get your copy from the link above to be sure it has not been tampered with.

Page: 1/10 Geo-Targeting Script from KeithJamesLock.com


Table Of Contents • • • • •

Script Files and Database Update Explanation (optional) Step 1 – Uploading/Installing The Script Step 2 – Re-Declare The Global Variable Step 3 – Displaying Unique Content For A Country Self Upgrading To php5 On GoDaddy (probably not necessary)

Page: 2/10 Geo-Targeting Script from KeithJamesLock.com


Script Files and Database Update Explanation Note: You may just skip to Step 1 if you wish. This section is optional. First and foremost you should have a copy of the script. If not, get the script here before you continue. Likely you would have already opened the zip file if you are reading these instructions. I'll assume that's the case. Below are the contents of the zip file. For the most part, you need not worry about these files. The database file is of the most importance. Contents Of Zip File geo Folder • GeoTargetingScriptInstructions.pdf – you are reading it • GeoIP.php • init.php GeoIP Folder • DMA.php • Location.php • GeoIP.dat – database which translates an IP Address into a country • DBUpdate.txt – verison of database (GeoIP.dat) included with this script Database File The database file, GeoIP.dat, is the file that holds all of the IP Addresses and the corresponding country the IP Address belongs to. Although not 100% accurate (all AOL users show as coming from the U.S.), it is very close. Over 99% accurate in fact. The database updates come free from MaxMind.com. They are updated monthly. I only ever update mine every 6 months but it's entirely up to you. Just overwrite the GeoIP.dat file on your server when you choose to update and you will be in business. Important: Page: 3/10 Geo-Targeting Script from KeithJamesLock.com


Be sure to upload it in “Binary” mode (explained later). Downloading And Decompressing The Updated Database File When you decide to update your database (optional), follow the instructions below. The following instructions involve uploading files with an FTP client. If you do not have an FTP client, please download and install one before you continue. You can download FileZilla for free here: http://download.cnet.com/FileZilla/3000-2160_4-10308966.html 1) Get yourself a utility to that handles decompression of .gz compressed files. You may already have one. The utility you use for .zip files may also handle .gz files. If not, here's a link to a free one: http://download.cnet.com/WinRAR/30002250_4-10007677.html 2) Visit http://www.maxmind.com/app/geolitecountry and under the Binary Format section, click the link that says: “Download the latest GeoLite Country Binary Format” and download the file to your desktop. 3) Extract/decompress the file. If using WinRar (download link above) then rightclick the downloaded file (GeoIP.dat.gz) and click “Extract Here”. A file called GeoIP.dat will appear on the desktop. That is the latest database for the GeoTargeting script. 4) Now replace the database file included in the script files in the “GeoIP” folder. You may do this before installing the script to Wordpress or after it is already installed. Note: You MUST upload the database file in BINARY mode. You may upload the other script files in Binary mode as well. Most FTP clients have the option to upload in binary mode. If using FileZilla, click on Transfer > Transfer Type > Binary. In general, it is safe to leave it on Binary mode for all future uploads. At least I haven't ran into issues. It's up to you.

Page: 4/10 Geo-Targeting Script from KeithJamesLock.com


Step 1 – Uploading/Installing The Script The following instructions involve uploading files with an FTP client. If you do not have an FTP client, please download and install one before you continue. You can download FileZilla for free here: http://download.cnet.com/FileZilla/3000-2160_4-10308966.html Note: You MUST upload the database file in BINARY mode. You may upload the other script files in Binary mode as well. Most FTP clients have the option to upload in binary mode. If using FileZilla, click on Transfer > Transfer Type > Binary. In general, it is safe to leave it on Binary mode for all future uploads. At least I haven't ran into issues. It's up to you. 1) Upload the entire “geo” folder (unzipped) into your current themes folder (for simplicity sake). For example: Upload to /wp-content/themes/{current theme}/ so you should then have: /wp-content/themes/{current theme}/geo/ with all of the necessary files in place. Remember: BINARY MODE :) 2) Browse to the Theme Editor area in your Wordpress Control Panel. Depending on your WP version that should be: Appearance > Editor. 3) Now on the right side, click on Header (header.php). 4) At the very top of the header file, immediately above the code that probably looks similar to: <!DOCTYPE html PUBLIC... type in the following code exactly: <?php include(TEMPLATEPATH . '/geo/init.php'); ?> 5) Save the file. At this point, when someone visits your blog, the script will store the visitors 2-letter country abbreviation into a global variable called $COUNRTY. Some of the possible values for that variable include: EU for Europe, AU for Australia, CA for Canada, CN for China, GB for United Kingdom, HK for Hong Kong, IE for Ireland, IN for India, IT for Italy, JM for Jamaica, NZ for New Zealand, US for United States, etc. The 2-letter abbreviations aren't always obvious so I attempted to include the most popular above. You may look at the GeoIP.php file to find more. The file won't always Page: 5/10 Geo-Targeting Script from KeithJamesLock.com


open properly in all text editors. Don't save the file if you aren't sure what you are doing. There should be no reason to edit the file ever anyways.

Page: 6/10 Geo-Targeting Script from KeithJamesLock.com


Step 2 – Re-Declare The Global Variable After completing Step 1 you have the ability to display alternate content in the header for each and every country! Very cool! But what about displaying alternate content elsewhere (other than the header)... A common use of the script is to show different ads in the sidebar based on the person's country. For example, say you are running an “acai berry” blog. You may have an offer/creative for the U.S. only which pays $37.00. You may also have another offer that caters to Canada, the U.S. and the U.K. which pays only $34.00. Before using this script, you may have opted for the second offer so you didn't miss out on the U.K. and Canadian traffic. However, the $3.00 extra you would get for the U.S. offer is very important to your bottom line, plus... what about all of the other countries visitors that may drop by? You can monetize that traffic as well with say... some Google AdSense. Re-declaring The Global $COUNTRY Variable The thing with Wordpress themes is that they, more often than not, use php calls such as get_sidebar(); and get_footer(); in the theme files to pull the contents of the sidebar and footer into the pages content. Well, when doing it that way, instead of using include files, the global variable that contains the 2-letter country abbreviation just ends up empty when called in the theme files. The workaround: Re-declare the variable... Where Do I Re-Declare The Global Variable? If you plan to show different content based on the visitors country... In the sidebar: then re-declare the variable in the sidebar.php file In the footer: then re-declare the variable in the footer.php file In posts: then re-declare the variable in the single.php file In pages: then re-declare the variable in the page.php On the main page: then re-declare the variable in the index.php file The filenames may differ depending on your theme, but mostly they should be the same. You may have to re-declare the variable in more then one file. That's the breaks! :) Page: 7/10 Geo-Targeting Script from KeithJamesLock.com


How Do I Re-Declare The Global Variable? To re-declare the global variable so that you have access to it's value in your themes, open the necessay page in your theme editor and type in the following code exactly: Note: for sidebar.php and footer.php, add it to the very top of the file. For any other file, add it just below the get_header(); call. Finally, the code: <?php global $COUNTRY; ?> Save the files and that's it. Step 3 shows how to display the content.

Page: 8/10 Geo-Targeting Script from KeithJamesLock.com


Step 3 – Displaying Unique Content For A Country At this point you have a variable that contains the 2-letter abbreviation of the country of the visitor to your blog. You can actually read that variable now that is has been redelared! Below I will show an example of code used for an “acai berry” blog. I will continue on with the same scenario described above... 1 offer for U.S. visitors, 1 offer for Canadian and U.K. vistors and Google AdSense for everyone else... Let's say we have a section in the sidebar for our ad that is 300x250 in size. Since I have re-declared the variable in sidebar.php I know what country the visitor belongs to. Here's the code that I would use: <?php if ($COUNTRY == 'US') { ?> Add the HTML to display your 300x250 ad for your $37.00 U.S. offer here! <?php } elseif ($COUNTRY == 'GB' || $COUNTRY == 'CA') { ?> Add the HTML to display your 300x250 ad for your $34.00 U.K./Canada offer here! <?php } else { ?> Add your 300x250 Google AdSense script here to be seen by all other countries! <?php } ?> Now, a unique ad should be running for each country. Good job! There are plenty of ways to use this script on your blog (or php-based web site). Be creative. The sky is the limit! If you like this script, please tell a friend to pick up a copy for themselves here: http://keithjameslock.com/wordpress-geo-targeting-script Page: 9/10 Geo-Targeting Script from KeithJamesLock.com


Self Upgrading To php5 On GoDaddy These steps are only necessary if you are hosted with GoDaddy AND you don't already have php5 running. There will be a file called .htaccess in the root of your blog installation on the server. Download that file (using FTP software) to your desktop. Open it with a decent text editor (like TextPad, because Notepad may jumble it up) and at the very top of the file add this line: AddHandler x-httpd-php5 .php Then save the file and re-upload. Your GoDaddy account should now be using php5.

Page: 10/10 Geo-Targeting Script from KeithJamesLock.com


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.