One way to add some custom class to a li
tag if the comment was posted by an administrator is to replace line
<li id="comment-<?php comment_ID() ?>">
with
<li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
This will add support for the default WP comments classes to your comments callback.
Once you do that add in your theme functions.php file the code below it will add class “posted-by-admin” to the li
tag classes if the comment author is an administrator.
add_filter( "comment_class", function( $classes, $class, $comment_id, $comment ) {
if( $comment->user_id > 0 && $user = get_userdata( $comment->user_id ) && user_can( $comment->user_id, "administrator" ) ) {
$classes[] = "posted-by-admin";
}
return $classes;
}, 10, 4 );
Related Posts:
- Add option to disable comments on a per posts basis?
- Paginate result set from $wpdb->get_results()
- Change Comment Author Display Name
- comments reply script not working
- Threaded comments – deleting parent comment leads to orphan comments
- How to remove commenters ability to add hyperlinks to comments?
- How can I edit the email sent when a new comment is received?
- How to remove or replace the log-in link for comment replies?
- Exclude internal links from comment moderation?
- Add Comment Custom Field
- Remove link preview in discussion dashboard
- Can’t add default comments to custom post type
- Does Akismet plugin expose any hooks, functions, class that can work with custom code?
- Comments Feed & Custom Post Statuses
- Multiple Comment Forms in a single page [closed]
- Why Allow Script Commands in Comments?
- How to no follow the paginated comments
- Remove “Comments are closed” Notice from Custom Post Type template
- Displaying comments with a walker: how to distinguish between parent and child comments
- Count parent comments & replies separately?
- How to modify comments form using comment_form()?
- Capability for allowing user to post own comments without moderation
- Comment count wrong with orphaned comments
- How would I count the number of times a comment meta field’s value is in a post’s entire comments?
- Get comment content by comment ID
- stackexchange-like submit comment window
- Retrieve comments from current post using SQL
- Comment_Reply_Link Not Showing?
- Display recent comments with gravatar and excerpts?
- Limit user to one comment
- Is comment metadata included in the export file?
- Get a List of All Commenters on the Current Post
- Display the number of unseen comments on a page since the user last visit
- Log in link not showing, Comment Issue
- Hide comments column in WordPress backend
- Removing the limit on the number of nested comments
- How to call my custom WordPress Comment form without getting the comments?
- How to moderate (manually approve) comments of a specific (registered) User
- How would I add the comment count to this sub-pages of current page snippet
- How can I test why the comment hook is not working?
- How to limit comment author to one comment per post
- Make WordPress process admin group comments using $allowedtags
- How do i remove “Website” field from WordPress comments
- WordPress comments work locally only?
- comment reply by email
- Incorrect redirection after commenting on custom type
- have_comments not true for logged out visitors?
- “Discussion” checkboxes unchecked by default on pages? [duplicate]
- How to disable or hide WordPress.com as a social media login option for Jetpack Comments [closed]
- How to limit comment indentations to one level?
- How can get comment link by comment id?
- How to amend time format of comments, using child-theme?
- Make user’s name display as the site name in comments if it matches certain roles
- Display avatar with comment form?
- Which hook do I use to edit pending comment count on wordpress dashboard?
- Add comment_id on Comments page within wp-admin
- Sent comments notifications to multiple users
- comment button shows only logged in users wordpress
- Getting comments of an specefic user
- I update a post and it creates a pingback? Any idea why?
- How can I embed comments plugin to my own website?
- get only one last comment from each post
- Limit action in comment according to IP
- How to get recent comment link
- stumped on add_action hook to delete_comment – any ideas?
- Can I create a new comment type?
- Allow tags between shortcode in comments
- How / where is the wp_query object created for RSS feeds?
- Separate page for comments using permalinks and add_rewrite_rule
- Return count for characters in the comment and perform action based on the length
- Cannot Remove Title Reply from Custom Comment Template for Signup Page
- How to make email field not required in comments?
- I have an odd field with a purple background, mentioning HTML-codes to use while leaving comments
- No comment Section but still got a Comment
- Order comments in admin by custom date
- WordPress Comments – Divide by conversation like Medium.com
- I want to limit registered user to 1 comment per post in WordPress
- What is wrong with this? [closed]
- Comment moderation
- I have tried using Plugins to remove 72K comments with no success
- Redirect first time comments
- Posting XML in comment section
- How to check if post has previous_comments_link() and next_comments_link()
- Comment text area in single blog post and show comments if approved
- Comments – Ensure the correct field is highlighted for nested replies
- How to ‘If Author’ Comments Check
- selectively disable akismet
- Disqus moderation page not working in WordPress admin section
- Comment Blacklist
- Comment forum to display under the comment you’re replying too
- WordPress error when sending comment
- WordPress Page Template: Comment Filtering with Querystring
- Modify “Recent Comments” List in WP-Admin
- Comment submission & navigation redirects to default language
- comments are going to spam
- How to hide the login / profile urls on top of comment box for a post
- wp_list_comments adds unnecessary elements
- How to enable truly anonymous posting in bbPress forums? [closed]
- comment_approved custom value
- TinyMCE in comment reply form showing toolbar but can’t edit reply