How To Highlight Authors Comments in WordPress

WordPress comments now already have gravatar icon associated with but its always good to have a distinction between authors comments and readers comments.

A while ago, I was looking around for how to make my own comments a different color on my blog. Most of the advice was along the lines of “Add code to check if the commenter’s email is the same as the email address of the blog’s author.” Can you spot the flaw in that logic? If a commenter knows the email address of the blog author, she could use the blog owner’s email address in her comment and get her own comment highlighted. Worse yet, someone could try to discover the blog owner’s email address by trying lots of email addresses until they saw their comments change to a different color.

wordpress comment hack

So I dug a little deeper and found a good answer on this support thread. The trick is simple: instead of checking the author’s email address, check their user id to see if it’s the user id of the blog owner. Pretty smart. After that, it was a simple matter of

1. Changing my theme to add an “authcomment” style

I edited style.css and near the bottom added these lines:

.authcomment {
background-color: #B3FFCC !important;
}

2. Editing my comments.php file to add a little code

My comments.php file had a line that looked like this:

<li class=”<?php echo $oddcomment; ?>” id=”comment…

and I changed it to more or less look like this:

<li class=”<?php
/* Only use the authcomment class from style.css if the user_id is 1 (admin) */
if (1 == $comment->user_id)
$oddcomment = “authcomment”;
echo $oddcomment;
?>” id=”comment…

That’s about it. Now I have a distinctive color for my own comments, so you can quickly scan a thread to see when I circle back around to leave a comment. What do you think of this trick ? Let me know in comments below.


Related posts:

  1. 40 WordPress Plugins to Improve your Blogs Performance
  2. Holiday WordPress: A Free WordPress Theme
  3. Create A Free Social Networking Website With WordPress
  4. A Game for Bloggers, BackLink to Me !
  5. Send emails without revealing your identity

Looking for something else?

Subscribe to our feeds via email.

(Dont worry we hate spam too!)

Enter your email address:

Delivered by FeedBurner

About inAm
Hi, my name is inAm, i am a tech-blogger and currently pursuing my degree in Software Engineering. I started blogging just for fun of being part of larger blogging community with similar interests but with time i have now developed addiction to it. I started Tempting Magazine in February 2009 and in just first two months my blog jumped to a Page Rank 3. If you like my posts please show some love by bookmarking them.

One Response to “How To Highlight Authors Comments in WordPress”

  1. Bottomless:

    Hi,
    I have already seen it somethere…
    Thank you
    Bottomless

Leave a Reply

About Me:

Sponsors

Search

Join My Community

Advertisement

Tempting Magazine on Facebook

Earn Blogging

Find Freelance Work Here

Powered by

Links

Computers/Tech blogs TopOfBlogs Internet http://www.wikio.com Tempting Magazine - Blogged