create widget to display comments in wordpress

  1. First, go to your WordPress dashboard.
  2. From the dashboard, navigate to "Appearance" and then click on "Widgets."
  3. Look for the "Text" widget and drag it to your desired widget area, such as the sidebar.
  4. Open the "Text" widget and paste the following code to display comments:
<?php
$args = array(
  'number' => '5', // number of comments to display
  'status' => 'approve', // only approved comments to display
  'post_id' => $post->ID, // current post ID
);
$comments = get_comments($args);
if($comments){
  echo '<ul>';
  foreach($comments as $comment){
    echo '<li>';
    echo '<a href="' . get_comment_link($comment) . '">';
    echo get_the_title($comment->comment_post_ID);
    echo '</a><br />';
    echo $comment->comment_content;
    echo '</li>';
  }
  echo '</ul>';
} else {
  echo 'No comments yet.';
}
?>
  1. Click "Save" to save the changes, and the comments should now be displayed in the widget area you selected.