How To Display A “Welcome Back” Message To Your Blog Visitors

newsletter

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:

<?php
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.

Sté Kerwer
Article written by Sté Kerwer (1994 Posts)
Bonjour from a french guy. My name is Sté Kerwer and Dukeo is my blog. I do most of the heavy lifting in here but from time to time, you may see some guest posts. To receive updates from Dukeo, follow us on Twitter or like us on Facebook.
If you enjoyed this article, Get email updates
JOIN FOR FREE

One Comment (Add one)

  1. mel

    thanks for the snippet :-)

Leave a Reply

When posting a comment, please use your personal name, not your business name. I find it a lot more interesting to talk with people instead of talking with brands.