When I use the following code, everything shows except the reply link! Anybody know what I've done wrong? I'd like the link to show up with the word 'Reply.'

Live example: http://themeforward.com/demo2/?p=1948#commentlist

In my header:

if ( is_singular() && comments_open() && get_option('thread_comments') )
  wp_enqueue_script( 'comment-reply' );

In comments.php:

<?php if($comments) : ?>  
    <?php foreach($comments as $comment) : ?>  
        <li id="comment-<?php comment_ID(); ?>">  
            <?php if ($comment->comment_approved == '0') : ?>  
                <p>Your comment is awaiting approval</p>  
            <?php endif; ?>
<?php if(function_exists('get_avatar')) { echo get_avatar($comment, '60'); } ?>
<cite class="fn"><?php comment_author_link(); ?> on <?php comment_date(); ?> at <?php comment_time(); ?></cite>
<?php echo comment_reply_link(array('depth' => $depth, 'max_depth' => $args['max_depth'])); ?>
            <?php comment_text(); ?>  

    <?php endforeach; ?>  
<?php else : ?>  
    <p>No comments yet</p>  
<?php endif; ?>  
  • 1
    Where are $depth and $args coming from? :::. I cannot see that max_depth in the Codex... ::::. The echo seems unnecessary to comment_reply_link. – brasofilo Nov 11 '12 at 1:42
  • 3
    To extend what @brasofilo said: either you're not showing your full code, or you've got undefined variables. What errors are generated if you set WP_DEBUG to true? Also: where do you define $depth and $args? And finally: why are you using a hard-coded comment list rather than wp_list_comments()? – Chip Bennett Nov 11 '12 at 16:49

My suggestion would be twofold:

  1. Ensure you are properly enqueueing the comment-reply script
  2. Replace your hard-coded comment list with wp_list_comments()

Enqueueing comment-reply

I would recommend hooking into comment_form_before():

function wpse71451_enqueue_comment_reply() {
    if ( get_option( 'thread_comments' ) ) { 
        wp_enqueue_script( 'comment-reply' ); 
// Hook into comment_form_before
add_action( 'comment_form_before', 'wpse71451_enqueue_comment_reply' );

Outputting the comment list

Using wp_list_comments() with default output in your code:

<?php if($comments) : ?>  
    <ol class="commentlist">
        <?php wp_list_comments(); ?>
<?php else : ?>  
    <p>No comments yet</p>  
<?php endif; ?>  

If you need specific markup for the comment list, you can pass a callback as a parameter to wp_list_comments(). But I would strongly recommend making sure everything works with the default output first, and then try to customize.

You can use your own custom markup in a callback, but you'll need to be sure to define the variables you're using, such as $depth and $args. If you can provide specific markup questions, I can help construct the callback.


You're simply missing the comment reply script. Enqueue it and you're don.

// Add this to your bootstrap, which should be hooked to `after_setup_theme`
# Add Scripts
add_action( 'wp_enqueue_scripts', 'wpse71451_comment_scripts', 0 );
 * Scripts
 * + Comment reply
 * @return void
function wpse71451_comment_scripts()
    # Comment reply script
    if ( 
        AND get_option( 'thread_comments' ) 
        wp_enqueue_script( 'comment-reply' );
  • thanks for the help, does this simply go in functions.php? That is where I've added it and I'm still not getting a link :-S – AndrettiMilas Nov 3 '12 at 19:13
  • This only works if you've "threaded comments" activated on your settings page. – kaiser Nov 3 '12 at 19:16
  • Unfortunately, this isn't working with threaded comments enabled. – AndrettiMilas Nov 3 '12 at 19:22
  • Check if the script is enabled and get loaded (FireBug or Chrome Dev Tools). Hint: This is only for singular posts/pages (see the conditional comment). – kaiser Nov 3 '12 at 20:08
  • Hmm... still can't figure it out. – AndrettiMilas Nov 3 '12 at 22:25

If you are using wp_list_comment with a custom callback, ie:

<?php wp_list_comments(array('callback' => 'my_wp_list_comment')); ?>

Then make sure that you pass the right depth parameters when calling comment_reply_link inside that callback, just like this:

    function my_wp_list_comment( $comment, $args, $depth ) {

        // ...blah

        // The actual comment

        // The comment reply link with the correct parameters
        comment_reply_link( array( 'depth' => $depth, 'max_depth' => $args[ 'max_depth' ] )
            , $comment->comment_ID
            , $comment->comment_post_ID

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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