Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sadly my "reply" link for threaded comments is not working.

The current situation:

First i load the comments reply script (check if scripts content load: works) into the <head> using two functions (the first wp_register_script() at the init hook, the second wp_print_scripts() at the wp_head hook):

Then i add the Reply link:

comment_reply_link( 
     array( 
         'reply_text'   => __( 'Reply', OXO_TEXTDOMAIN )
        ,'depth'        => isset( $args['args']['depth'] ) ? $args['args']['depth'] : (int) 3
        ,'max_depth'    => isset( $args['args']['max_depth'] ) ? $args['args']['max_depth'] : (int) 5
     )
    ,get_comment_ID()
    ,$post->ID
);

which produces this html-output (example)

<a onclick="return addComment.moveForm("comment-11", "11", "respond", "149")" href="/wordpress/?p=149&cpage=2&replytocom=11#respond" class="comment-reply-link">Reply</a>

I got everything according to any recommendation i read:

My comments are within a <div id="comments"> and the comments form above it within a <div id="respond">.

I still get dropped to the #respond-anchor and the comment form above the comments (http://localhost/wordpress/?p=149&cpage=2&replytocom=11#respond), instead of getting the comment form displayed below the comment i want to reply to.

What may i do wrong?

Google, tutorials, how-to and else were so far of no help. Everything seems to be according to the recommended standard...

Thanks a lot.

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

Don't link the script file directly. Enqueue it instead, e.g. in functions.php:

function mytheme_enqueue_comment_reply() {
    // on single blog post pages with comments open and threaded comments
    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { 
        // enqueue the javascript that performs in-link comment reply fanciness
        wp_enqueue_script( 'comment-reply' ); 
    }
}
// Hook into wp_enqueue_scripts
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_comment_reply' );

You can also do this, in the document head, prior to the wp_head() call:

<?php
// on single blog post pages with comments open and threaded comments
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { 
    // enqueue the javascript that performs in-link comment reply fanciness
    wp_enqueue_script( 'comment-reply' ); 
}
?>

EDIT:

Hooking into wp_head, rather than e.g. wp_print_scripts, is important. The wp_print_scripts does not work in the same way that wp_print_styles does, to output stylesheet links.

So: if you're using wp_print_scripts, change the hook to wp_head.

EDIT 2:

Based on your pastebin-linked code, have you tried the following, to rule out potential issues?

  1. Remove callback function from wp_comment_list()
  2. Move wp_comment_list() call to before comment_form() call
  3. Remove the argument array from comment_form()

I don't know that any of those will solve your problem, but they may help us track down its origin.

share|improve this answer
1  
wp_print_scripts doesn't work in the same way that wp_print_styles works. You need to use wp_head directly. –  Chip Bennett May 10 '11 at 2:49
1  
Are you using the comment_form() function to generate the comment-reply form markup? If not, can you post your markup? –  Chip Bennett May 10 '11 at 13:30
1  
The only thing out-of-the-ordinary I see there is that your comment-reply form comes before the comment list, though I can't imagine why that should matter. See troubleshooting edits to answer, above. –  Chip Bennett May 10 '11 at 15:13
1  
Glad you got it sorted out! This was a tricky one. –  Chip Bennett May 10 '11 at 15:48
1  
If you hook into 'comment_form_before' you can drop the check for comments_open() and the script will be enqueued in the footer. –  toscho Feb 22 '12 at 4:48
show 4 more comments

protected by Community Jun 27 at 9:04

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.