ERIC
ERIC

Reputation: 63

Wordpress Reply Comment Link

It feels like I have tried so many things, so I am coming here for help. Things that have worked for other people have not worked for me. I am trying to have nested comments, but I cannot get them to work. My situation is odd because the reply comment form displays underneath the comment which you are trying to reply to, but when you hit post, it does not work. Also, if you look at the URL it does not change from #comment-(some value) to #respond-(some value). I can see that the js is being properly loaded in my Chrome Inspector tab. I am properly enqueuing the comment reply.

I have tried enqueuing the script differently, resetting my permalinks to the default, and numerous code changes but can't seem to get anything to work. Any help would be greatly appreciated. I have tried searching around but have not been able to find a solution or someone with a similar issue.

[Edit]: I cannot see the comment-reply.js being properly loaded in my inspector tab. I tried forcing it to load by placing blahblahblah above my wp_head in my header.php, and it loaded but had no effect.

Here is the code I am using and the file it is in:

Single.php:

<?php   

        if( comments_open() ) {

                comments_template();

            } 

            ?>


        <?php endwhile;

    endif;

?>   

Comments.php:

<?php if( have_comments() ): ?>

<h4 id="comments"><?php comments_number( 'No Comments', 'One Comment', '% Comments' ); ?></h4>

<ol class="commentlist">
<?php wp_list_comments(array(
    'callback' => 'ericshio_custom_comments',
    'max-depth' => 'x',
)); ?>
</ol>

<?php else : ?>  

    <p class="no-comments">No comments yet</p>  

<?php endif; ?>

<?php

    $comments_args = array(
        // Change the title of send button 
        'label_submit' => __( 'Post', 'ericshio' ),
        // Change the title of the reply section
        'title_reply' => __( 'Write a Reply or Comment', 'ericshio' ),
    );

?>

<?php comment_form($comments_args); ?>

Functions.php:

/* Custom Comments */

function ericshio_enqueue_comments_reply() {
    if( get_option( 'thread_comments' ) )  {
        wp_enqueue_script( 'comment-reply' );
    }
}

add_action( 'comment_form_before', 'ericshio_enqueue_comments_reply' );

function ericshio_custom_comments($comment, $args, $depth) {
    $GLOBALS[' comment '] = $comment; ?>
  <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
  <div id="comment-<?php comment_ID(); ?>">
      <div class="comment-author vcard">
          <?php echo get_avatar($comment, $size='48', $default='<path_to_url>' ); ?>

          <?php printf (__('<cite class="fn">%s</cite> <span class="says"> says:</span>'), get_comment_author_link()) ?>
</div>

      <?php if ($comment->comment_approved == '0') : ?>
      <em><?php _e('Your Comment is Awaiting Moderation.') ?> </em>
      <br />
      <?php endif ; ?>

      <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link($comment->comment_ID )) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time() ) ?> </a> <?php edit_comment_link(__(' (Edit) '), '   ', ' ') ?> </div>                            

      <div class="comment-wrapper">

        <?php comment_text() ?>

      <div class="reply">
          <?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth'] ))); ?>

      </div>

      </div>

  </div>
<?php 

}

Upvotes: 1

Views: 1894

Answers (1)

Noman
Noman

Reputation: 1487

You should have to read this because the same problem with me in past so i solved this issue from here.

https://codex.wordpress.org/Template_Tags/wp_list_comments#Comments_Only_With_A_Custom_Comment_Display

Reference: codex.wordpress.org

EDIT:

In header.php, add this line wp_head():

if ( is_singular() ) wp_enqueue_script( 'comment-reply' );

That code adds the comment-reply javascript to the single post pages.

So, your comment form has a new parameter that you have to add:

<?php comment_id_fields(); ?>

<a id="respond"></a>

<h3><?php comment_form_title(); ?></h3>

This makes a comment form title of "Leave a Reply"

<?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?>

The %s will be replaced with the person's name. This will only happen when the javascript isn't working.

<div id="cancel-comment-reply">

<small><?php cancel_comment_reply_link() ?></small></div>

These are just general principles that you’ll need to use.

Refernce: OttoPress

Upvotes: 1

Related Questions