Title: Custom Callback for Comments
Last modified: February 16, 2020

---

# Custom Callback for Comments

 *  [ilfedevisio](https://wordpress.org/support/users/ilfedevisio/)
 * (@ilfedevisio)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/custom-callback-for-comments/)
 * Hi, I don’t know why but my code isn’t working for a custom callback in the wp_list_comments(),
   but let me explain; this is the code that works well:
 *     ```
       <?php
       if( ! function_exists( 'better_comments' ) ):
       	function better_comments($comment, $args, $depth) {?>
       		<span> <a href="#"><i class="fa fa-reply"></i> <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?></a></span>
       <?php
       	}
       endif;
       ```
   
 * So, the comment_reply_link() works… But, when I add some html customization, 
   I got this error: “Notice: Undefined index: max_depth” pointing on the array 
   inside comment_reply_link(). This is the code with html customization:
 *     ```
       if (!function_exists('better_comments')):
       	function better_comments($comment, $args, $depth) { ?>
       	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
       		<div class="row comment clearfix pl-3 pb-2">
       			<div class="col-auto p-0">
       				<?php echo get_avatar($comment,$size='40',$default='',$alt='', $args=array('class'=>'comment-thumbnail')); ?>
       			</div>
   
       			<div class="col">
       				<div class="bg-dark p-2 comment-radius">
       				<p class="m-0 px-2"><span class="commentatore"><?php comment_author(); ?> </span><?php echo get_comment_text(); ?></p>
       				</div>
       				<span><?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?></span>
   
       			</div>
       		</div>
       <?php
       	}
       endif;
       ```
   
 * Can someone solve this issue? I really don’t know why with some html customization
   I got that error.
    -  This topic was modified 6 years, 3 months ago by [ilfedevisio](https://wordpress.org/support/users/ilfedevisio/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [ilfedevisio](https://wordpress.org/support/users/ilfedevisio/)
 * (@ilfedevisio)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/custom-callback-for-comments/#post-12443254)
 * UPDATE: The problem seems to be in the
    `<?php echo get_avatar($comment,$size
   ='40',$default='',$alt='', $args=array('class'=>'comment-thumbnail')); ?>`
 * The $args creates this problem, because if I remove it everything works… How 
   can I add a class to that avatar without breaking the code?
    -  This reply was modified 6 years, 3 months ago by [ilfedevisio](https://wordpress.org/support/users/ilfedevisio/).
 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/custom-callback-for-comments/#post-12443347)
 * Your function has a parameter called $args. When you call `get_avatar`, you reset
   that variable to contain an array with one element (class). Then you use the 
   $args in the call to `comment_reply_link`, as if it should be the one passed 
   into the function.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom Callback for Comments’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 2 participants
 * Last reply from: [Joy](https://wordpress.org/support/users/joyously/)
 * Last activity: [6 years, 3 months ago](https://wordpress.org/support/topic/custom-callback-for-comments/#post-12443347)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
