DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

What about displaying a customized welcome message to your readers? Do you know that you can use the cookie sended by the comment form to get the name of the reader? Let’s use it to create a very cool welcome message.

Nothing hard here: Simply paste the following code wherever you want on your template.

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

First, we checked if the visitor have a cookie called comment_author_xxx. If he have, we can get his name and display it on the welcome message. If the cookie doesn’t exists, we simply welcome the visitor as a guest.

Credits goes to ifohdesigns for this awesome script!

Leave a Comment

Your email address will not be published. Required fields are marked *