Post Pic

How to: Style author comments in WordPress 2.7

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

Dec 31 2008 09:32

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. :)

Dec 31 2008 12:40

Thanks for sharing. It is nice to see they added in new wp version this css class to save us time.

Dec 31 2008 12:50

Nice tip shared here. Tweeted this one :)

Dec 31 2008 19:13

Excellent. I will publish this trick (in spanish) on my blog today :D

I love this blog :D

Maxi Sanchez

Dec 31 2008 20:24

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.

Jan 03 2009 12:41

Excellent small tip.

It’s also a plugin that does this, but it’s always cooler to do it yourself :D

Jan 04 2009 07:33

It couldn’t be mor simpler. Thanks for sharing!

Jan 04 2009 22:44

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.

Jan 04 2009 23:54

@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. :)

Jan 10 2009 00:19

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?

Jan 10 2009 01:58

This tip is excellent! Easy to implement and very helpful. Thanks!

Jan 11 2009 01:07

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.

Jan 11 2009 01:11

@malcolm: I think that something like:
li.depth-1.bypostauthor, li.depth-2.bypostauthor {
//CSS styling
}
should work :)

Jan 11 2009 01:23

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.

Jan 18 2009 23:32

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

Feb 26 2009 12:27

I wanted to style just the admins comments, how can I do that ?

Mar 30 2009 09:57

That’s for the tip on that new class. (Couldn’t find it in the codex)

May 06 2009 21:19

oh this is just what i was looking for. thanks!!

Jun 17 2009 09:44

Thank’s! ;)

Aug 26 2009 11:49

thanks for the nice tutorials
but it anit work in wordpress 2.8.2
can u help me with new h.ack?

Nov 11 2009 22:41

thank you for this tip! I never knew about this until now ;)

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required