How to Have Infinite Replies with WordPress Threaded Comments

WordPress doesn’t allow to have infinite replies beyond the maximum nested comment depth. In this tutorial, I’ll show you how to create a “Reply” link for all threaded comments, regardless of the depth.

Table of Contents

In this screenshot, I’ve set the nested comments level to three:

WordPress Nested Comments Three Levels Deep
WordPress Nested Comments Three Levels Deep

WordPress will nest comment replies to this depth and then stop showing the “Reply” link at the bottom of every comment, as shown here:

WordPress Comment Reply Missing on Maximum Depth
WordPress Comment Reply Missing on Maximum Depth

Because of this limitation, visitors can’t have an ongoing conversation on your site, thereby stifling debate. The code below fixes this problem.

Code for Infinite WordPress Replies

To solve the above problem, paste the following code into your theme’s functions.php file, or better yet, use a custom plugin for code insertion. Whichever way you choose, here’s the code you need:

// 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="#comment-'.$comment_id.'" data-commentid="'.$comment_id.'" data-postid="'.$post_id.'" data-belowelement="comment-'.$comment_id.'" data-respondelement="respond" data-replyto="Reply to '.$author.'" 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');

The above code will replace the default WordPress Reply link with an identical one. But this time, it will include the link for all comments – including those with a maximum threaded depth. With the above code, the same WordPress comment thread in the first screenshot looks like this:

WordPress Reply Link on Most Deeply Nested Comment
WordPress Infinite Replies Even at Maximum Nested Comment Depth

Now your visitors can continue the conversation forever.

No Need to Modify Core WordPress Files

Earlier tutorials required you to modify the core comment-template.php WordPress file. I don’t recommend this approach because any WordPress update will wipe out your changes and can create security vulnerabilities. The solution above works with all themes and is perfectly safe. If you use a custom plugin for WordPress code, your changes will persist even between updates.

Why Increasing the Max Depth via Code Doesn’t Work

WordPress lets you set a maximum threaded comment level of 10. Some solutions require you to increase this limit using the “thread_comments_depth_max” filter like this:

add_filter( 'thread_comments_depth_max', function( $max )
{
    return 20;
} );

The above code will double the maximum nested depth of your comments. Unfortunately, each successive comment level will indent further until the comment is utterly unreadable at the full depth. This isn’t a sustainable solution for ongoing conversations.

Allow Flat Inline Replies Like on Facebook

Social networks have found the best way to have a comment section. They have a maximum nested comment depth of two, and all replies after that are flat. There’s no indentation, but the “Reply” button is always visible no matter the length of the conversation or the number of people participating. With my suggested code, you, too, can replicate the flat comment structure of networks like Facebook and Twitter on your WordPress website.

About Bhagwad Park

I've been writing about web hosting and WordPress tutorials since 2008. I also create tutorials on Linux server administration, and have a ton of experience with web hosting products. Contact me via e-mail!

Comments

  1. Hello,
    my theme does not seem to support threaded comments and I want to add them. I also want them to be infinite. So I added your code to functions file. Now I can see the Reply button (great!), but when I reply to comment 1, then comment 2 is created, but they are both on the same level. On your example you show that comment 2 is indented to the right and all the subsequent comments are then on the same level. My ALL comments are on the same level, even if I use the Reply button for the first time. Do you have any idea, what is the issue here? Thank you very much,
    Elena

    Reply

Speak Your Mind

*

WP-Tweaks