Allow Infinite Replies with WordPress Threaded Comments

Note: There’s an updated method for this that doesn’t require you to modify core theme files. Check out the link at the bottom of the article.

It’s been around five years since WordPress introduced threaded comments in 2008 allowing viewers of a blog to reply to comments with indentation instead of having a “flat” structure. This allows us to follow a discussion or debate between two people without having to move up and down the page repeatedly. WordPress also allows us to set the indentation level giving us a hard limit to the number of nested replies we can have. Unfortunately if we want infinite replies, we run into one of two problems.

Too Many Nested Replies

The maximum level of indentation allowed is 10. If your WordPress theme is not designed properly, the nested replies would fall into smaller and smaller columns sometimes becoming unreadable with only one a few characters per line! What we want is to continue to allow people to reply without additional indentations.

No Reply Button

We run into another problem. When the indentation limit is reached, we can’t reply anymore. Before that, every comment has a “Reply” link at the bottom. But if you want to respond to a comment that has already reached the maximum indentation, you’ll be forced to either start a new comment thread altogether, or to click the “Reply” link of another comment above that.

wordpress threaded comments-1

This can be problematic because the other person may not receive a notification that you responded to them. Here’s what the lack of a “Reply” link looks like:

Infinite Replies without Indentation

Here’s the ideal situation: we set the indentation levels for the purpose of appearances. Given our blog theme and taste, we don’t want them to go beyond a certain limit. But the reply button should always be available. Any additional comments that are added on to one that is already at the max limit  will inherit the indentation of the parent comment.

This mimics the way comments are handled on social networks like Facebook and Google+. They effectively have an indentation level of 2 and allow infinite replies. So how do we go about replicating this on WordPress? Normally you would expect some plug-in or the other to do this for you but so far I haven’t found any. So we’re going to have to delve into the code and make a small change on our own.

Modifying comment-template.php

It wasn’t easy for me to find out where the code for the reply button was being generated. After sniffing about in various files, I finally found it in the “comment-template.php” file. It’s located in the wp-includes folder. Use a text editor like Notepad++ to edit it. If you try and do so in basic Notepad, it’ll just be a jumble of characters without any structure. Notepad++ is by far one of the best and easiest programs to quickly modify a bit of general code.

As of WordPress 3.6.1, we need to delete two lines starting at line number 1044. Look for the following piece of code:

if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] )
		return;

It’s located in the get_comment_reply_link function (big surprise!). As you can see, it checks to see whether the comment is at the maximum indentation level and if so, doesn’t return anything. Just delete these two lines, save the file, clear your cache, and voilà!

This simple change magically adds a “Reply” link to each and every comment on your blog regardless of indentation levels. Now you too can effortlessly replicate the format found on social networks but with the additional ability to setting the indentation level yourself. And that’s how you get infinite replies on WordPress threaded comments. Don’t forget to take a backup of comment-template.php in case something goes wrong!

Update: I’ve found a workaround that generates the “Reply” link from scratch and doesn’t require core file modifications.

What do you think of this post?
  • You're an asshole (1)
  • Agree (0)
  • Don't Agree but Interesting (0)

1 2

Comments

  1. Thanks a lot ! That’s exactly what I was looking at !

    Reply

  2. Dan Kirshner says
1 2

Speak Your Mind

*