Blog Madness

e-Marketing tips

Saturday, February 2, 2013

Only show ads if a visitor comes from a specific site

Scenario:

  • You are running Wordpress.
  • You only want to show specific ads to visitors coming from the domain foobar.com and google.com.

Code:

In your functions.php add:

function fromspecificsite(){ $ref = $_SERVER['HTTP_REFERER']; $SITES = array('foobar.com', 'google.com'); foreach ($SITE as $source) { if (strpos($ref,$source)!==false) return true; } return false; }

In your template add:

if (function_exists('fromspecificsite')) { if (fromspecificsite()) { INSERT YOUR CODE HERE } }