Dukeo » WordPress » “Welcome Back” Message: How To Greet Your Blog Visitors

“Welcome Back” Message: How To Greet Your Blog Visitors

Steven One response WordPress

When you’re blogging, you definitely want to create a connection with your readers to gain their attention and their trust. A good way to do that is to display a customized “welcome” message to your visitors.

You might not know it, but when people are leaving a comment on your WordPress blog, a cookie gets written on their computer. This information is used to pre-fill the comment form when they are returning to your blog.

An interesting thing is that you can use the information in this cookie to get the name of the reader and use it to create a personalized “welcome back” message.

To implement this function, simply paste the following code wherever you want to display the welcome message:

if(isset($_COOKIE['comment_author_'.COOKIEHASH])) {
  $lastCommenter = $_COOKIE['comment_author_'.COOKIEHASH];
  echo "Welcome Back ". $lastCommenter ."!";
} else {
  echo "Welcome, Guest!";

This code checks if the visitor has a cookie on their computer called comment_author_x. If the cookie exists, the code will display a “welcome back” message with the person’s name. If there is no cookie, we will simply welcome the visitor with a generic message.

If you enjoyed this article,
Get email updates

Join for Free »

One Comment

  1. thanks for the snippet :-)