Two Ways to Add Custom Messages to WordPress, Part 2

(TRANSCRIPT)

This is Part 2 of our tutorial on ways to add custom messages to your WordPress blog or website. Most marketing experts agree that return visitors are more valuable to you than new ones. Today, we’re going to look at a way to personally greet your return visitors with a custom message- which is a great way to add interactivity to your site.

We do this by accessing cookies that were left on their machine from the last time they visited you, and left a comment. Yes, this only works if they left a comment in the past.

Here’s the code you need:

<?php if(isset($_COOKIE[‘comment_author_’.COOKIEHASH])) {
$lastCommenter = $_COOKIE[‘comment_author_’.COOKIEHASH];

echo “Welcome Back, “. $lastCommenter .”!”;

} else {

echo “Welcome, and thanks for visiting!”;
} ?>

What this does is check for the existence of a cookie on the visitor’s machine that signifies that he or she has left a comment in the past. If so, it displays the message “Welcome Back,” and then the name left in the comment. If there is <em>no</em> cookie, it displays a default message instead. In this case, “Welcome, and thanks for visiting!”

You can change the text after “echo” to anything you like, of course- and you can add styles, using CSS, to make the message pop.

So again, let’s add this bit of code to my existing WordPress blog. In the theme editor, open up the Sidebar, and copy and paste the code right here.

Let’s reload the page… and there’s our message!

………………

Get targeted, quality traffic to your site with a guest posting service