WordPress comment cookies not being set

For quite some time I thought WordPress wasn’t setting the comment cookies properly, because when I made comments the fields wouldn’t remain populated after I commented. I finally realized that if you’re logged in, you don’t have to worry about the fields at all because it pulls the name, e-mail address and URL from the user profile. This wasn’t very intuitive and the values still could have been filled in to the fields, but I realized that my theme just needed to exclude the name, e-mail and URL field if the user was logged in.

I believe there are lots of themes out there that would benefit from this change.

To update a theme, just use the conditional provided at the bottom of the get_currentuserinfo() page on the WordPress Codex.

Here’s what I added to my theme.

<?php if ('' == $user_ID) { ?>

. . . (The Name, E-mail and URL fields)

<?php } ?>

Comments

 (Post a comment) | Comments RSS feed
  1. That works, but PHP would probably recommend the following:

    . . . (The Name, E-mail and URL fields)

    Comment by Chad on February 6, 2007 @ 9:17 am
  2. Haha, it’s not letting me post any php code… but what I posted was to change the following:

    if (” == $user_ID)

    to

    if (!isset($user_ID))

    Both would work, but the latter is more PHP efficient.

    Comment by Chad on February 6, 2007 @ 9:20 am
  3. Chad: Thanks for the correction. I usually use isset() in my code, but took their example from the codex.

    Comment by dan on February 6, 2007 @ 10:52 am

Comments are closed