Each time a visitor leaves a comment on your WordPress blog, it automatically stores a cookies – comment_author, comment_author_email and comment_author_url. So each time that particular visitor returns and want to leave another comment, the person don’t have to fill out those necessary ‘Personal Information’ (Name, E-mail and URL) again on the comment form.
According to WordPress Codex, WordPress checks for the existence of their cookie, and then tries to compare their hashed data with the values stored in the WordPress database
.
We can actually use it to do some cool stuff. Here share the codes that I’ve been using in this blog as an example.
- Code snippet 1
As seen on my comments form heading :
<h3 id="respond"> <?php if ( ($comment_author != "") && (!$user_ID) ) { ?> Want to share something <?php echo $comment_author; ?>? <?php } else { ?> Share Your Comments <?php } ?> </h3>Based on the condition, IF the
$comment_authorvariable is NOT empty and NOT logged-in user; display Want to share something COMMENT_AUTHOR? or ELSE display Share Your Comments. - Code snippet 2
If you want to use it outside comments for example on the front page :
if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) { $comment_author = $_COOKIE['comment_author_'.COOKIEHASH]; echo 'Welcome back, '.$comment_author.'!'; }It will display as Welcome back, COMMENT_AUTHOR!
- Code snippet 3
Do not display advertisement to returning visitor, logged-in user and during post preview. Originally taken from Binarybonsai.com.
global $cookiehash; if ( !isset($_COOKIE['comment_author_'.COOKIEHASH]) && !is_user_logged_in() && !is_preview() ) { echo 'Advertisement goes here..'; }Does anyone really cares about this?
So there you have it folks! I know there’s probably a better way to do this and many things you can actually do with it. Like usual have fun playing with it.
cool. nnt test kat blog
nice idea, rendering a roccuring blog visit more personal
Oookay !
So this is the trick lah.
Cool.
canggih!
cool… bole aku mencobanya nanti!
Hello world
Hi!
Some helpful information here. I’m sorry for beeing a little off-topic, but I want to ask you about the design of this site. Did you make this template yourself or got it from any templates website? Looks pretty cool for me. Personally I use Joomla, but am looking for something new.
Really superb codes. Marvelous. I was searching for something having that effect on k2 themes that welcome back comment’s authors, where they don’t have to input all their details on a revisit for a comment when I fell on this.
Nice one Zeo. :-)