User Agents

Web browsers and everyday web tech, explained

Show Comments on WordPress Homepage

· 5 min read · Settings and Privacy

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

By default, WordPress does not display comments on the homepage, which typically shows a list of recent posts. Enabling comments directly on the homepage requires modifying how your theme renders content. This guide walks you through the process of showing comments on your WordPress homepage, whether you want to display comment counts, recent comments, or full comment sections. While WordPress supports comments on posts and pages, the homepage (especially if it's a blog index) usually excludes them. With a few adjustments to your theme or settings, you can make comments visible and interactive directly from the homepage.

What You'll Need

  • A self-hosted WordPress website (wordpress.org, not wordpress.com)
  • Access to your WordPress admin dashboard
  • Ability to edit theme files (via Appearance > Theme Editor or a child theme)
  • Basic understanding of PHP and HTML (for code modifications)
  • An active theme that supports comments (most standard themes do)
  • Optional: a child theme to preserve changes during updates

Step-by-Step

  1. Log in to your WordPress admin dashboard using your username and password.
  2. Navigate to Settings > Discussion. Ensure that "Allow people to submit comments on new posts" is checked. This ensures comments are enabled globally.
  3. Go to Settings > Reading. Confirm that your homepage displays your latest posts (not a static page). If you're using a static front page, showing full comments on the homepage becomes more complex and may require template-specific changes.
  4. Visit Appearance > Theme Editor. In the list of theme files on the right, locate and click on index.php or home.php (if your theme uses it). This is the template that controls your homepage layout.
  5. Find the loop section in the file, typically marked by <?php while ( have_posts() ) : the_post(); ?>. This loop displays each post on the homepage.
  6. Inside the loop, after the content or excerpt, add the following code to display comment counts: <?php comments_popup_link('No comments yet', '1 comment', '% comments'); ?>. This shows a link that opens comments in a popup.
  7. To show a preview of recent comments instead, add this code where you want comments to appear:
    <?php
    $comments = get_comments(array('number' => 5, 'status' => 'approve'));
    foreach($comments as $comment) {
      echo '<div class="recent-comment">';
      echo '<strong>' . $comment->comment_author . '</strong>: ';
      echo wp_trim_words($comment->comment_content, 10);
      echo '</div>';
    }
    ?>
    This displays the latest five approved comments with author and a short excerpt.
  8. To load full comment sections inline on the homepage, add <?php comments_template(); ?> inside the loop after the post content. Be aware that this can make the homepage very long and slow to load if multiple posts have many comments.
  9. Click Update File to save your changes. Always back up the original file before editing.
  10. Visit your homepage to see the changes. Refresh the page and check if comments or comment links appear as expected.
  11. (Optional) If you're using a caching plugin, clear the cache to ensure changes appear immediately.

Common Mistakes

  • Editing the wrong template file (e.g., editing single.php instead of index.php). Always confirm which file controls the homepage layout.
  • Adding comments_template() outside the loop, which may result in no comments being displayed or errors.
  • Not backing up theme files before editing, risking site breakage if syntax errors occur.
  • Expecting full comment forms to work on the homepage without additional JavaScript or AJAX support, especially when multiple posts are displayed.
  • Ignoring performance: loading full comment threads for multiple posts can slow down the homepage significantly.

Tips

  • Use a child theme to make changes. This prevents losing modifications when the parent theme updates.
  • Consider showing only comment counts or recent comments instead of full threads to keep the homepage fast and clean.
  • Style comment display using CSS. Wrap comment elements in classes and add custom styles in Appearance > Customize > Additional CSS.
  • Use a plugin like "Recent Comments" widget if you prefer a simpler, non-code approach to showing comments on the homepage.
  • Test changes on a staging site first, especially if your site gets high traffic.
  • Ensure comments are moderated properly—spam comments on the homepage are more visible and harder to manage.

Troubleshooting

If comments don't appear after following the steps, first verify that comments are enabled for individual posts. Edit a recent post and check the Discussion meta box—"Allow comments" must be checked. If comments are enabled but still not showing, ensure the PHP code was added in the correct location within the loop. A syntax error in the code (like a missing semicolon or quote) can break the page. If the site shows a white screen, restore the original file from backup and re-add the code carefully. If using a page builder or block-based theme (like with Gutenberg), standard template edits may not apply—check theme documentation or use a custom HTML block with JavaScript-based comment loading. If comments appear but are unstyled, add CSS rules to format them properly. If the site uses aggressive caching, clear all caches (server, plugin, and browser) to see updates.

Frequently Asked Questions

Can I show full comment sections on the homepage?

Yes, but it's not recommended for performance. Use comments_template() inside the loop, but expect slower loading times.

Why aren't comments showing after I added the code?

Check that comments are enabled in Settings > Discussion and on individual posts. Also, confirm the code is placed correctly inside the loop in the right template file.

Can I show only recent comments without code?

Yes. Use the built-in "Recent Comments" widget in Appearance > Widgets and place it in your homepage sidebar or footer.

Will this work with any WordPress theme?

Most themes support comments, but custom or block-based themes may require different methods. Always test on a staging site first.

Is it safe to edit theme files?

It's safe if you back up files first and use a child theme. Avoid editing live sites without a backup.

Do comment counts update automatically?

Yes, comments_popup_link() dynamically displays the current number of comments for each post.