Javascript and WordPress Threaded Comments

Sometime after WordPress 2.7 and before WordPress 2.9.2, I lost a key functionality within WordPress. It’s threaded comments.  I blame myself for constantly tinkering around with the theme. I must have deleted a key piece of code somewhere in the theme that prevented threaded comments from working.

For those not familiar with WordPress, the threaded comments functionality allows the “comment form” to jump underneath a specific comment when a “Reply” link is clicked. Clicking “Cancel Reply” restores the “comment form” to its original position. When a comment is submitted, the comment is placed directly underneath that specific comment.

In my case, the threaded comment function still worked, sort of, but not quite the way it was supposed to. I did some digging around. After reading a couple of articles, I finally found what was missing in my WordPress theme. It’s a tiny Javascript command that you place in header.php.

This tiny Javascript makes the comment form jump from one place to another. Make sure this code is in header.php just before the <?php wp_head(); ?> command.

<?php if ( is_singular() ) wp_enqueue_script( ‘comment-reply’ ); ?>