If you’re the owner of a popular WordPress website, I can guarantee you that you’ve had problems with long threaded comments. These are twofold. First, you have to think about what level of indentation you want to allow. By default, WordPress allows you to nest comments up to a maximum of 10 levels.
While this may sound like a lot, the flipside is that with each successive level, the width of the comment form becomes smaller and smaller leading to absurd situations like the one shown in the screenshot below:
As you can see, there’s barely any space for the individual words of the comment to be seen! I’m sure everyone will agree that this is an untenable solution. It looks ugly, and makes a mockery of any kind of thoughtful discussion. The most common solution of course is to simply restrict the number of nested comments to a more manageable number – like say 4. While this preserves the look of the website, it creates serious hurdles for nested replies that go beyond the limit. After that number has been reached, there will be no further “Reply” links available as seen here:
This forces the responder to search for a higher-level comment that has the Reply button available. But this means that the thread is broken and readers can no longer follow the discussion. Even worse, it the person whose comment is being replied to may not get a notification. A big mess all around!
The Ideal Solution
What we’re looking for is a solution based on the way comment threads function on social networks or on third-party comment systems like Disqus or Livefyre. There’s no limit to how many times you can reply to someone. But the indentation stops at a specified level. Further replies no longer make the comment box grow smaller and smaller. This has the twin benefits of presenting the discussion in an easy-to-read format while at the same time allowing people to continue talking to each other.
Of course, you can install a third-party commenting system on your own blog, but that comes with a whole lot of trade-offs. How do we replicate this functionality using the native WordPress commenting system?
A Controversial Solution?
Everyone knows that you must never mess with WordPress core files. The warnings are reasonable given that every time there is a version change, the files are overwritten and you lose whatever modifications you make. Here’s a humorous meme depicting the horror with which some developers view WordPress core modifications.
So be warned – the solution I’m about to propose requires a modification of the WordPress core. You just need to delete two lines in the “commment-template.php” file, but I found that it’s the only way to consistently add a “Reply” link to every single comment regardless of the theme. You have been warned! So here goes.
Just Remove these Two Lines
Navigate to your WordPress wp-includes folder and search for the comment-template.php file as shown in the screenshot below.
Copy it over to your desktop, and use a text-based editor like Notepad++ to search for the following two lines and delete them:
if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) return;
This little snippet of code checks to see whether the indentation level has been reached and if so, returns null in the function that creates the Reply link. By deleting it, we ensure that the button is always displayed even if we’re at the max nested level. Take a backup of your existing comment-template.php file, and transfer over the modified one via FTP.
Problem solved! WordPress now allows you to reply to every single comment regardless of indentation. So simply set it to some sensible number like 3 or 4. I implemented the solution on my blog with an indentation level of four. You can see in the screenshot below, that every comment has a Reply link while at the same time not reducing the width of the comment section beyond a certain limit.
If you want to exactly replicate Facebook or Google+ comments, simply set the indentation level to 1. The reason why this requires a modification of the core file, is because the “add_filter” functionality is added after this check towards the end of the function. Meaning that any attempts to hook in will fail since the code will never even reach it in the first place.
Keep in mind that every time you update your WordPress installation, this little change will be overwritten even though it won’t affect the appearance of your site in any other way. Despite the hassle, I’ve found it worth my while to keep deleting these lines in order to make my comments section a bit more sane and easier for users.