Debugging Why Your Comment Reply Links Aren’t Showing in WordPress

June 18th, 2014 - Posted by Steve Marks to PHP, Web Development.

Comments are a great addition to any blog powered by WordPress. Not only do they influence interaction between your users, but they can also be beneficial when it comes to SEO. With WordPress’ built in capabilities to handle comments, adding them to any blog post or news article is relatively straight forward.

It was exactly this that we were doing today on a site; adding comments to a company’s blog. Adding the ability to comment was easy enough, but we also wanted users to be able to reply to individual comments. After an hour or so of struggling to achieve this we finally cracked it. Initially, no matter what we tried, there would just be no link output whatsoever.

What follows is our findings during the process and, hopefully, the definitive guide to debugging why comment reply links might not appearing:

Check 1: Enqueue comment-reply.js

For the replying of comments to work there needs to be a certain JavaScript file included. This JS file, called ‘comment-reply.js‘, comes with WordPress and is used to display the form next to the comment being replied to. To add it you can simply enqueue this script like any other using the wp_enqueue_script() function like so:

wp_enqueue_script("comment-reply");

Or, even better:

if ( is_singular() ) { wp_enqueue_script("comment-reply"); }

The above will only include the script on single pages, as opposed to every page on the site.

Don’t know if this file is being included successfully? A quick way to check if this file is being included is to view the page source code. Do a search for ‘comment-reply.js‘ and, if it finds a result, then you know it’s included successfully.

Check 2: Are nested threads turned on in WordPress?

There is an option in WordPress which specifies whether nested comments should be allowed.

WordPress Nested Comments
To activate or check this setting navigate to ‘Settings > Discussion‘ within WordPress.

Check 3: Try using the default WordPress comment layout

If you’re trying to use your own comments template you are probably using something like so:

wp_list_comments('type=comment&callback=mytheme_comment');

As a test try changing this back to:

wp_list_comments();

This will use the default comment layout and, if the ‘Reply‘ link appears here, you can then guarantee it’s something to do with your bespoke layout.

Check 4: Try using the code from the WordPress Codex

In the WordPress Codex (here) there is an example of how to make a bespoke comment layout.

If you’ve tried to hack together your own layout, try temporarily swapping it out for the example provided to see if that works. Again, if it does work in this scenario then it must be something to do with your bespoke layout.

Check 5: Make sure you have any required parameters set

The function to output the actual reply link is called comment_reply_link(). In our scenario we weren’t including any parameters when calling this function and the reply link failed to appear. By looking at the example from Check 4 above and using the same parameters as there the reply link then began to show.

Check 6: Get inside the WordPress code

If all else fails it might be worth opening up the relevant WordPress code and adding some debugging output in there to discover at which point it’s failing. The file where all the magic happens is called ‘/wp-includes/comment-template.php‘ with the specific code occurring on line 1294 (as of WordPress 3.9.1).

I hope that by now you’ve worked out why your reply links aren’t showing. If you discover another reason why yours aren’t appearing leave a comment and I’ll add it to this above.

This entry was posted on Wednesday, June 18th, 2014 at 7:12 pm by +Steve Marks and is filed under PHP, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.
Comments...

Fear not, we won't publish this

Comments (0)

No comments have been left yet. Be the first