Welcome! If you like our Blog so please Follow this blog and also +1 this blog here---->

Sunday, 28 October 2012

Pin It

How to highlight author comments in WordPress

How to highlight author comments in WordPress

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.

 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. 
Bilal ahmed Janjua Post Author

Hi. My name is Bilal Ahmed. The Author and the Owner of this blog. I posted daily new Posts about Blogger and Wordpress. So, Stay tuned with me.