Comment_Reply_Link Not Showing?

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

Read More

In my header:

<?php
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(); ?>  

        </li>  
    <?php endforeach; ?>  
<?php else : ?>  
    <p>No comments yet</p>  
<?php endif; ?>  

Related posts

Leave a Reply

3 comments

  1. 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(); ?>
        </ol>
    <?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.

  2. 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 ( 
            is_singular() 
            AND get_option( 'thread_comments' ) 
        )
            wp_enqueue_script( 'comment-reply' );
    }
    
  3. 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:

    <?php
        function my_wp_list_comment( $comment, $args, $depth ) {
    
            // ...blah
    
            // The actual comment
            comment_text(); 
    
            // 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
            );
        }
    ?>