Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/comments template


The comments_template filter hook filters the path to the theme template file used for the comments template. It is part of the comments_template() function.

The comments_template filter can be used to load a custom template form a plugin which replaces the theme's default comment template.


(string) (required) The path to the theme template file.
Default: None


A plugin can register as a content filter with the code:

<?php add_filter( "comments_template", "my_plugin_comment_template" ); ?>

Where my_plugin_comment_template is the function WordPress should call when the comment_template() function is called on the theme. Note that the filter function the plugin defines must return the a full path to a template file or the resulting page will be blank.

This is an example of loading a different comments template for a custom post type:

function my_plugin_comment_template( $comment_template ) {
     global $post;
     if ( !( is_singular() && ( have_comments() || 'open' == $post->comment_status ) ) ) {
     if($post->post_type == 'business'){ // assuming there is a post type called business
        return dirname(__FILE__) . '/reviews.php';

add_filter( "comments_template", "my_plugin_comment_template" );

The example code will load the template file reviews.php located in your plugins folder for CPT called business else uses default template.

Change Log

Since: 1.5.1

Source File

comments_template is located in wp-includes/comment-template.php


See also index of Function Reference and index of Template Tags.