Get FREE email updates »
INSTANT ACCESS

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

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.

If you enjoyed this article, Get email updates
JOIN FOR FREE

One Comment (Add one)

  1. mel

    thanks for the snippet :-)