Due to the new comments system in WordPress 2.7, and the wp_list_comments() function, you have to change the way you style author comments. But don’t worry, I’m going to show you how to do.
Due to the new comments system in WordPress 2.7, and the wp_list_comments() function, you have to change the way you style author comments. But don’t worry, I’m going to show you how to do.
With previous WordPress versions, you had to use some hacks to be able to give a special style to author comments. But this isn't needed with the brand new WordPress 2.7: A specific CSS class is automatically added by WP to author and registered users comments.
To style author and registered users on WordPress 2.7, simply paste the following code in your style.css file, and style at your taste
li.bypostauthor {
/* CSS styles for author comments */
}
li.byuser {
/* CSS styles for registered users comments */
}
33 Responses
Nice, one less plugin to worry about. But I am really lazy to make changes to comments block in my theme… I mean it works, why bother.
Thanks for sharing. It is nice to see they added in new wp version this css class to save us time.
Nice tip shared here. Tweeted this one
Excellent. I will publish this trick (in spanish) on my blog today
I love this blog
Maxi Sanchez
Thanks for this. I’ve been putting off going to 2.7 on my blogs, but for one at least this would make the upgrade worth the effort.
Excellent small tip.
It’s also a plugin that does this, but it’s always cooler to do it yourself
It couldn’t be mor simpler. Thanks for sharing!
Thanks for this, I tried it out and it works well. I have just run into a slight problem.
I styled the ‘byuser’ class to change the background as well as the link states. I make use of threaded comments. In my comments both the background and link states are set as I want them. The problem comes in when someone replies to my comments. When this happens the background reverts back but the new link states are retained for the new comment.
Any advice would be appreciated.
@Lyndi
If I am right you have background for link [not] defined for whole comments in .commentlist class. For registered users you override it with li.byuser. When someone replies to you those replies are inside your li so styling cancels global list styling which is farther.
May be totally wrong, there are a loooot of classes WordPress generates in new comments and threads with nested list don’t help at all.
ok, but what if I run a membership WP-powered site?
I just want to highlight my (admin) comments.
Since it’s a membership site, users are registered in WP’s DB, and I suppose all comments coming from registered users get styled.
How do you style only the admin ones?
This tip is excellent! Easy to implement and very helpful. Thanks!
How does the bypostauthor one interact with the other CSS styles for comments? I’m using li.depth-1, depth-2 etc to style the threaded ones – but I the bypostauthor stylings I set don’t seem to come through. To be honest, I think I’ve made a bit of a mess of the CSS. Ho hum.
@malcolm: I think that something like:
li.depth-1.bypostauthor, li.depth-2.bypostauthor {
//CSS styling
}
should work
Cool, I’ll give that a go. Now I’ve just got to get the subscribe to comments by email plugin working, and that’s it for 2009. Not.
For some reason this is not working for me. I have 2.7 and i am very familiar with how CSS works. Could it be because of the theme im using?
Im new to wordpress so if someone can help me out here i would appreciate it.
Thanks
I wanted to style just the admins comments, how can I do that ?
That’s for the tip on that new class. (Couldn’t find it in the codex)
oh this is just what i was looking for. thanks!!
Thank’s!
thanks for the nice tutorials
but it anit work in wordpress 2.8.2
can u help me with new h.ack?
thank you for this tip! I never knew about this until now
Trackbacks: