Home » Web Tutorials » WordPress » How to Fix WordPress Comment Reply Not Working with Uncaught HierarchyRequestError?

How to Fix WordPress Comment Reply Not Working with Uncaught HierarchyRequestError?

Recently, we noticed that clicking the “Reply” button in the comments section did not load the comment form below the selected comment. After some investigation, we found an error in the browser’s developer console starting with “Uncaught HierarchyRequestError…”. If you are facing the same error or the comment reply feature is not working on your WordPress site, here is how to troubleshoot and resolve the issue.

Identify the Conflicting Script

The issue may occur primarily when you are logged out of the WordPress admin dashboard. Therefore, if you are currently logged in, open your site in a separate browser or an incognito/private window.

  • Right-click anywhere on the page and select “Inspect,” or press F12 to open the browser’s Developer Tools.
  • Go to the “Console” tab and check for errors.
  • You may see an error similar to the following, pointing to a specific script:
Uncaught HierarchyRequestError: Failed to execute ‘insertBefore’ on ‘Node’: The new child element contains the parent.
Uncaught HierarchyRequestError in Browser Console

The script might be one of the following:

  • comment-reply.min.js: WordPress’s built-in threaded comment script.
  • jquery.js or load-scripts.php: A generic jQuery operation.
  • A theme or plugin script: Often involving insertBefore or insertAfter operations.

In our case, comment-reply.min.js was causing the problem because WordPress could not load the comment form inside the comments section. Once you know that the problem is related to the comment reply script, it is easier to focus on the relevant WordPress settings and configurations. If you are not comfortable performing these troubleshooting steps on a live site, create a staging site or localhost setup and test there.

1. Check the Comment Settings of Your Theme

The error occurs when JavaScript tries to move a DOM element into one of its own descendants, creating an invalid HTML structure. For WordPress comment forms, this usually means the reply script is targeting the wrong container. If your theme manually moves form elements, it might be targeting an element that already contains the element it is trying to move.

Many WordPress themes modify the comment setup as part of their blog post customization options. Go to the “Appearance > Customize” section and look for blog post or comment-related options. Some premium themes also provide a separate theme options panel where you can search for blog post and comment settings. For example, the popular Astra theme offers an option to move the comment form above all existing comments. This was the problem in our case. The form did not load when clicking the “Reply” button in a comment thread because it had already been moved above all the comments.

Simply moving the form back below the comments, which is the standard position, fixed the issue.

Change Comment Form Position in Astra Theme

Disable any specific theme settings that affect the comments section and test whether this fixes the problem.

2. Check Plugins Affecting the Commenting Setup

Next, check whether any plugins are modifying the comments section. Here are some common changes that plugins can make to the default WordPress commenting system. The example plugin is also mentioned in the bracket.

  • Removing the comment author link (Perfmatters).
  • Modifying the comment-reply script to stop spam comments from bots (Forget Spam Comments).
  • Using AI or other spam-detection methods to block spam comments (Akismet).
  • Lazy loading comments (Lazy Load Comments).
  • Hiding the comments section behind a button (a theme function or the Lazy Load Comments plugin).
  • Advertisements in comments loop (Raptive Ads or other ad network)

Plugins such as Forget Spam Comments may cause problems because they modify the comment reply script, which can conflict with your theme. Turn off the relevant plugin settings or temporarily deactivate the plugin and test again.

Forget Spam Comment Plugin

As mentioned earlier, use a separate browser or an incognito/private window for testing because the issue may occur only for logged-out users.

3. Check the comment-reply.js Script

Generally, the comment-reply.js script moves the reply form below the selected comment. It expects the comment container and reply form to use specific ID attributes.

  • Check your comment IDs: Your comment li or div elements must have a unique ID, usually in the format id="comment-{ID}". Open your theme’s comments.php file and make sure the comment wrapper includes an ID similar to id="comment-".
  • Check the respond ID: The reply form container must have id="respond".
  • Ensure the script is enqueued: Make sure your theme loads the WordPress comment reply script. If necessary, add the following code to your theme’s functions.php file:
wp_enqueue_script('comment-reply');

If you are using a child theme, make the changes there instead of directly editing the parent theme files. This prevents your changes from being overwritten during a theme update.

4. Enable Debugging for More Details

Sometimes, the problem can occur because scripts are not functioning correctly due to an underlying PHP error. Since the browser console only shows frontend errors, you can enable WordPress debugging to check for additional details. Add the following lines to your wp-config.php file:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

Check the /wp-content/debug.log file for PHP errors that might be affecting the page output or breaking the JavaScript functionality. Once you identify which line, plugin, or theme file is causing the error, it becomes easier to fix the issue. Remember to disable debugging after troubleshooting on a production site.

5. Check JavaScript Optimization Settings

JavaScript optimization can also interfere with the WordPress comment reply script. If you use a performance or caching plugin, temporarily disable options such as:

Test the “Reply” button after disabling each option. If the feature starts working, exclude comment-reply.min.js from the relevant optimization setting. This is particularly important when using CDN optimization features or hosting-level performance tools. For example, all sites hosted on SiteGround come preinstalled with the Speed Optimizer plugin, which enables frontend optimization features by default. Therefore, you need to disable those features or exclude the comment-reply script and test your site again.

JavaScript Optimization by SiteGround Speed Optimizer Plugin

Common Troubleshooting Tips

Most JavaScript errors in WordPress are caused by conflicts. If you cannot find the issue using the above steps, follow these general troubleshooting guidelines to narrow down the cause. As mentioned earlier, perform these steps in a staging or localhost environment whenever possible to avoid affecting visitors on your live site. You can also get help from your developer or hosting company if needed, though some providers may charge for advanced troubleshooting.

  • Go to “Plugins > Installed Plugins,” deactivate all plugins, and check whether the error disappears. If it does, reactivate the plugins one by one until the error returns. The last activated plugin is likely the cause. If the error persists with all plugins deactivated, the issue is likely related to your active theme.
  • Temporarily switch to a default WordPress theme, such as Twenty Twenty-Five. If the error disappears, the problem is likely in your custom theme’s comments.php, functions.php, or another comment-related template file.
  • Make sure WordPress, all plugins, and your theme are updated to their latest stable versions. If the error started after a theme or plugin update, roll back to a previous stable version and test again.
  • Search the theme or plugin support forum for similar issues. Sometimes, other users have already reported the problem and a fix is available.
  • Clear all cached files. Browser, plugin, server, and CDN caches can serve outdated JavaScript files. Clear your browser cache and purge the cache from plugins such as WP Rocket, WP Super Cache, or W3 Total Cache. If you use a hosting CDN or server-level cache, purge that cache as well.

After making changes, test the comment reply feature and confirm that the HierarchyRequestError error no longer appears in the browser console.

Leave a Comment

Your email address will not be published. Required fields are marked *