Geeky Nuggets

Referrer Wordpress Plugin

September 24, 2004 | 2 Minute Read

Referrers is a plugin I coded to show the most recent referring urls to a particular post. I had seen the wp-refer plugin from NoPrerequisite but couldn’t put it on my blog without hacking because it uses the meta fields to store its data, and as I display the metadata for other purposes in each post, it would get fairly cluttered.

Also, I am using the very good StatTraq plugin, so I thought I could make use of the fact that it already records referrers.

To install :

  • Download and install Stattraq.
  • Download post_referrers.php.txt
  • Rename to post_referrers.php
  • Or get the gzip file and uncompress it.
  • Upload the resulting file to /wp-content/plugins
  • Activate it in your admin interface

Using it is simple:

Add the following code to your index.php file, within the loop

 post_referrers(8, "<li>", "</li>", "No referrers", "self");

Where ‘8’ is the number of referrers to show, ‘<li>’ is the text to show before each link, ‘</li>’ is the text to showafter each link, ‘No referrers’ is… you guessed it! the text to show when there are no referrers yet and the last option marks the excluded hosts. If you use ‘self’, internal referrers only will be hidden. Otherwise, you can write a list of hosts (domain names) to ignore like this: “google.com yahoo.com example. org” and so on…

See it work at the bottom of this page, and leave a comment in case of problems.

Version 0.21 and up use Google redirection to help prevent referrer spam.

En Fran?ais