• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero Blog

NameHero Blog

Web Hosting Tips & Resources From NameHero

  • Hosting
    • Web Hosting
    • VPS Hosting
    • WordPress Hosting
    • WooCommerce Hosting
  • Reseller
  • Enterprise
  • Domains
  • Account
  • Blog Home
  • Categories

How To Implement Unlimited Comments In WordPress

Bhagwad Park

Published on: August 12, 2019

Categories: WordPress 0

I’ve written before about the insufficiency of 3rd party comment systems like Facebook, and recommended that you stick with the default, native WordPress comment system. Even though there are plugins for comments that make use of your own database, you never know if they’re going to stick around for long or be updated to comply with newer WordPress versions. In general, I’ve found that the native comment system is the best in the long run, even with all of its existing flaws. It’s a masterpiece of compromise between competing elements.

However, years of running an opinionated blog have taught me that the most difficult thing in maintaining a comment section, is how to deal with long comment threads. Understandably for some topics, discussions can get quite heated. And sometimes, two people start a looooong discussion that can go on for days! Handling these threads properly is key.

Currently No “Unlimited” Replies in WordPress

Let’s say you have a discussion thread that’s getting a lot of replies. Plenty of back and forth between two individuals. You’ll soon see something like this:

Threaded Comments Unable to Reply

What’s happened here, is that after a certain point, the “Reply” button vanishes and there’s no way to further respond to the comment above. It’s for this reason mainly, that people switch to third-party comment systems like Disqus and Facebook. It can get very frustrating for a person to be unable to reply to the last comment. Instead, they need to have workarounds like replying to the 2nd last comment the other made, and that completely breaks the comment thread.

You can of course, change the number of allowed nested threads via the WordPress settings as shown here:

Limit to Threaded Comments in WordPress

In this screenshot for my test blog, the number of nested comments is “5”. And that’s why the comment replies stop at the fifth comment. So you might be tempted to increase the comment threading levels to some huge number, like say “1000”.

But this presents another problem. By default, WordPress indents comment replies. And so if the number of threads is too large, the comment replies become thinner and thinner, eventually leading to silliness like a single character per line. The entire thread becomes unreadable, and counterproductive.

What we’re looking for is a solution that does two things:

  1. Allows unlimited comment replies
  2. Stops indenting after a certain point.

Code to Make it Happen

So here’s the code I developed to fix these two problems. If you don’t know how to add custom code to WordPress with the functions.php file, check out NameHero’s tutorial on the same:

// Add a custom reply link for infinite comments

function add_a_reply_link($comment) {
    $temp = get_comment_id();
    $comment_handle = get_comment($temp);
    // $comment_handle = get_comment(get_comment_id());
    $comment_link = get_comment_link($comment_handle);
    $comment_id = get_comment_id();
    $post_id = get_the_id();
    $author = get_comment_author();
    
    $comment= $comment . '<p><a class="comment-reply-link" href="'.get_page_link().'?replytocom='.$comment_id.'" aria-label="Reply to '.$author.'">Reply</a></p>';

    return $comment;
}

add_filter('get_comment_text', 'add_a_reply_link');  

// Remove the default reply link

function remove_reply_link() {
    return '';
}
add_filter('comment_reply_link', 'remove_reply_link');

What this text does, is that it removes the default “Reply” link supplied by WordPress, and adds in our own custom Reply link while leaving everything else unchanged. After you’ve saved your code, you can see the results here:

In this screenshot, the indentation stops at comment 5 like before. But now each comment has a “Reply” button at the bottom regardless of comment depth! This means that your visitors can now post an unlimited number of comments in reply to each other, and not have to worry about the whole thing looking terrible!

In my opinion, this is a must-have piece of code on any WordPress website with an active community and lots of discussions!

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!

Most Popular Posts

Speed up your site: solving the WordPress slowdown

NameHero’s Recommended WordPress Plugin and Theme Setup (2023)

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • Website Performance
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • Domains
Help & Support
  • NameHero Blog
  • Knowledgebase
  • Announcements
  • Affiliates
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2023 NameHero, LLC. All rights reserved.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA