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:

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:

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:
- Allows unlimited comment replies
- 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!

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!
Leave a Reply