This tutorial was written with plugin authors in mind.

I’ve been struggling for a while to make WordPress use another file than the comments.php file that comes with a theme. In my case it was to be able to have a global comments.php file that all themes use, unless that have their own.

In WordPreciousss this is solved with simply creating a new function called precious_comments you have to use instead of comments_template. But it is really too much work to go through several themes - and especially if you are running a WordPressMU site where it can be hundreds - to make the changes.

So finally I found a better way of doing this without anyone having to touch any theme core files.

In the comments_template function there’s a filter simply called comments_template you can use to tell what file to load and where the file is located.

So a very basic example of usage:

function my_comments_template() {
$path = ABSPATH . '/templates/index.html';
$file = '/2008/05/how_to_replace_commentsphp_with_another_file_the_simple_way/comments.html':
return $path . $file;
}
add_filter('comments_template','my_comments_template');

This function will tell WordPress to use a file called comments.php ($file) in a directory called templates ($path) instead of the comments.php template file that comes with a theme.

And as you probably see it a very simple function which of course can be extended anyway you like. But if you are a plugin author who have created a plugin that replaces a theme’s comments.php file, you should try this out.