Site logo

Archived topic

How To Add A Verified Badge To Authors and Comment reply

1 reply · Started by Aditya Kumaar on December 2, 2021

Viewing posts 1–2 of 2

How To Add A Verified Badge To Authors and admin comment reply. Please provide a small code. Like this- Image

Hi there,

best i have in my snippets is to add a CSS Class to the Comment if the user is an admin or the post author.

1. Add this PHP Snippet:

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" ) || $comment->user_id === $post->post_author ) ) {
        $classes[] = "verified-user";
    }
    return $classes; 
}, 10, 4 );

How to add PHP: https://docs.generatepress.com/article/adding-php/

2. Add this CSS to place some text and a tick beside the comment author name:

.verified-user .comment-author cite:after {
	content: 'verifed user \2713';
	margin-left: 10px;
}
This archived topic is closed to new replies.