Note that with the following:
add_filter ('comments_template', 'fbcommentbox', 100);
we expect fbcommentbox()
to return the path to the new comments template file. The default is the path of comments.php
.
If you create the fbcommentbox.php
file in your theme, then you could try:
add_filter( 'comments_template', 'fbcommentbox', 100);
function fbcommentbox( $theme_template )
{
// Path to our new comment template file
$new_theme_template = get_template_directory() . '/fbcommentbox.php';
// Override if it exsits
if( file_exists( $new_theme_template ) )
$theme_template = $new_theme_template;
return $theme_template;
}
If the file fbcommentbox.php
doesn't exists then the default one is loaded instead. For a child theme we would use get_stylesheet_directory()
.
Here's a shorter version:
function fbcommentbox( $theme_template )
{
return locate_template( 'fbcommentbox.php' );
}
where the locate_template()
does all the hard work.
Update
But you mentioned you wanted to override wp_list_comments()
instead.
Here's a way to do that by changing the echo
argument to false
:
add_filter( 'wp_list_comments_args', function( $args )
{
// Display fbcommentbox.php
get_template_part( 'fbcommentbox' );
// Disable output of wp_list_comments()
$args['echo'] = 0;
return $args;
} );
and output instead the fbcommentbox.php
template.