There are a number of plugins available in WordPress that make it easy to prompt users to subscribe to your blog based on where they landed on your website.
It’s convenient, but if you’re interested in providing a specific message – not just a request for subscription – you may need to roll your own code.
It’s easy, too.
If you’re interesting in targeting a user coming from Google, then add the following snippet to your code:
[cc lang=”php”]
if (strpos($_SERVER[HTTP_REFERER], “google”) == true) {
// target your Google visitor here
}
[/cc]
Similarly, you can determine if a user is from Twitter by adding the following code:
[cc lang=”php”]
if (strpos($_SERVER[HTTP_REFERER], “twitter.com”) == true) {
// target your Twitter visitor here
}
[/cc]
If you want to get more creative, you can include both of these in a single conditional statement. The implementation of the actual conditional can be something as simple as a simple message, too:
[cc lang=”php”]
if (strpos($_SERVER[HTTP_REFERER], “google”) == true) {
echo “
Hello Google-based Visitor!
“;
} else if (strpos($_SERVER[HTTP_REFERER], “twitter.com”) == true) {
echo “
Hello Twitterer!
“;
}
[/cc]
In both cases, you’ll need to determine where to place this code. If you want to show something near the top of the page, the header file may be the best.
If you’re looking to include it at the beginning of each post, then it may make more sense to place it in the post file.
Speak your mind...