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

StevenOne responseWordPress

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.

Learn how I made $33,543 online in the past 12 months.

Simply input your best email below to get started.

One Comment

  1. thanks for the snippet :-)

Learn how I made $33,543 online in the past 12 months.

Simply input your best email below to get started.

No thanks, I have enough money