Passing arguments to wp_list_comments callback function

One can customize single comment markup using the callback argument in wp_list_comments like this:

$args = array( 'callback' = 'my_callback', 'avatar_size' = 48, 'type' = 'comment' );
wp_list_comments( $args );

The question is, how to pass arguments to that my_callback function? Already it gets three:

function my_callback( $comment, $args, $depth )

But I need to add my own 4th argument

Topic comments-template comments Wordpress

Category Web


You may use the use in function:

function my_callback( $comment, $args, $depth ) use ( $my_arg1, $my_arg2, ... )

Finally I figured it out. you may simply add your arguments to the wp_list_comments as associative key => value pairs like this:

$args = array( 'callback' => 'my_callback', 'avatar_size' => 48, 'type' => 'comment', 'arg1' => $arg1 );
wp_list_comments( $args );

and then in your my_callback you have:

function my_callback( $comment, $args, $depth )

where you have access to $arg1;

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.