Missing comment-reply JS out-of-the-box

When I download and install the sage theme, the comment replies don’t work. When I click on Reply on a comment, it doesn’t move the comment form to the proper position and I get this error in the console:

Uncaught ReferenceError: addComment is not defined
at HTMLAnchorElement.onclick ((index):181)
onclick @ (index):181

Line 181 in index is this:

<div class="reply"><a rel='nofollow' class='comment-reply-link' href='#comment-101175' onclick='return addComment.moveForm( "div-comment-101175", "101175", "respond", "14898" )'>

I checked the history and it was removed in this commit (9.0.0-alpha.1: August 30th, 2016) but it doesn’t say why: https://github.com/roots/sage/commit/d217ba6

I was able to fix for myself by adding it back here:

/**
 * Theme assets
 */
add_action('wp_enqueue_scripts', function () {
    wp_enqueue_style('sage/main.css', asset_path('styles/main.css'), false, null);
    wp_enqueue_script('sage/main.js', asset_path('scripts/main.js'), ['jquery'], null, true);
    wp_enqueue_script( 'comment-reply' ); // this fixes comment replies
}, 100);

Can anyone please elaborate on why was this removed? Is this a bad practice? What’s the best way to fix it then?

Yikes, not exactly sure why I made that change but definitely didn’t expect it to cause any errors. We should probably just re-add https://github.com/roots/sage/commit/d217ba6

Alright, do you want to do that, or how can I help?

This would be good/easy PR for anyone wanting to dip their hands into open-source :smiley:

Oh I see that @danielroe just fixed it 2 days ago. Thanks so much!

1 Like