Show the user profile picture, profile link, user badges and display name to your comments

This guide will help you show the user profile picture, profile link, user badges and display name to your comments. Each theme is different but often you have a comments.php file, open that file and find this part: wp_list_comments( array( ‘callback’ => ‘presscore_comment’ ) ); The callback will be different for each theme, so you just need to find this function inside your theme files, in this example, we are using the dream-theme and the callback presscore_comment is located in functions.php this can be different for each theme though. The callback function includes your actual comment template. Once you locate this function, edit the following parts to in the function to replace existing comments and integrate UserPro stuff in it. Here are steps:

function presscore_comment( $comment, $args, $depth ) {
global $userpro;
}

echo get_avatar( $comment, 60 );

This short line will display user avatar, 60 is the size you want. You can customize the comments avatar size using this option. That’s it for the avatar, UserPro avatars now integrated in comments.

<?php
if ($comment->user_id) {
printf('%s', '<a href="'.$userpro->permalink( $comment->user_id ).'">'.userpro_profile_data('display_name', $comment->user_id) . '</a>');
?>
}
else {
printf('%s', get_comment_author_link());
}
?>

What did we do? Simply we need to check if the commenter has an ID (profile) by testing $comment->user_id, then we display his permalink, and profile data (display name) that’s all. If he does not have an account, the normal author link will display.

<?php
echo userpro_show_badges($comment->user_id, $inline=true);
?>

That will show the user badges for comment author. Ofcourse you need to check that he is not a guest using $comment->user_id check.

  • STEP 1: Define global of UserPro : You must define this line global $userpro; just after the callback function has started. In this example, it looks like this :
  • STEP 2: Use UserPro profile picture (avatar) : Change the part that displays user avatar in your comments to:
  • STEP 3: Display user profile link & name : Find the part that displays comment author link or name and replace it with this function:
  • STEP 4: Display user badges :To display user badges in your comments, simply add this code to your comments function where you want to show the badges (This can be different for your needs) maybe beside commentor name is a good option. So you just need to insert the following snippet to show the badges for any registered user.

Was this article helpful?

Related Articles

Leave A Comment?