There’s always something to howl about.

Have another cookie? Targeting content to two different kinds of first-time visitors to a WordPress.org weblog

Dustin had a post last night that made me rethink the ideas I posted the other day on using a cookie to modify a WordPress.org weblog’s default behavior for first-time visitors.

Clear as mud?

Starting with version 2.0, WordPress introduced the idea of an optional intro.php file that would be a sticky first post. In other words, the file, truly a pseudo-post, could be shown first to every reader who landed on the top-level page of the weblog. That way, you can do all your welcoming house-keeping with new users.

Too cool. What’s the problem? Most people showing up at your weblog are not new users, so you’re going to hammer that intro.php nail into their heads again and again.

And Dustin raised another problem: Many people arriving at your weblog for the first time will be coming in from search engines, from your RSS feed or from deep links on other sites. Those folks are never going to see intro.php, because they won’t enter the weblog from the top level.

The code I wrote the other day solved both of these problems, but with a one-size-fits-all solution. What if you want to issue a special introduction only to top-level first-time visitors? What if you want to address only those people coming in via deep links into your weblog? What if you want to say something different to each type of visitor?

I amended the code today to take account of these two different entry scenarios. Using this version you can have an intro.php file for people who enter your weblog for the first time through the front page. The cookie associated with that expires in 60 days, so that only people who have been away for a long while will see it more than once.

You can also have another file called singlePostIntro.php (or whatever) for people who come in via a hard click from a search engine, an RSS feed or another web site. That cookie lasts for two weeks. The point is to address infrequent visitors who come in via deep links differently, in the hopes of persuading them to become subscribers.

You can see this version in action at Distinctive Phoenix. We’re assuming that top-level entrants are coming at least modestly pre-sold on the idea of the blog, so we’re closing on the idea of becoming part of the community. For deep-linked entrants, we’re asking for a smaller commitment: Since you’re already here, stick around to see what we’re all about. In both cases, the idea is to guide the first-time visitor toward greater involvement.

Both cookies are set on every entry, so you’ll have to clear the two cookies after every entry to see the alternate behavior.

And: Where the two introductory files at Distinctive Phoenix are all text, those files could contain any PHP that will run outside of the WordPress “Loop” — globally-available WordPress functions, calls to plug-in functions or custom PHP coding. For example, you could parse an inbound URL for a search string, then craft a link to an internal WordPress search on that keyword. That would make everything you have on the subject available, where the external search engine only targeted one post.

In principle, all of this is really straightforward. The tricky part is that no two WordPress themes are exactly alike. If you want to play with this code — and you don’t blanch at the idea of playing with code — say so.

Technorati Tags: , ,