Separate Page for Post Comments

The code below designed as a plugin and creates a separate comments page for single post of the site. A new page .../comments/ appears for each post, it displays comments of the post.

Let's do the stuff.

Create a plugin file, name it comments-page-plugin.php. Add to it the code below and connect the file in theme's function.php file or as normal WordPress plugin:


 * Plugin Name: Kama Post Comments Single Page
 * Description: Creates single page for post comments.
 * Version: 1.0
 * Author: Kama
 * Author URI:

$Kama_Separate_Comments_Page = new Kama_Separate_Comments_Page;

class Kama_Separate_Comments_Page {

	static $page_title_patt = "Comments for %s";

	function init(){

		add_filter( 'query_vars',       [ $this, 'query_vars' ] );
		add_action( 'init',             [ $this, 'add_endpoint' ] );
		add_action( 'single_template',  [ $this, 'template_redirect' ] );
		add_filter( 'get_comment_link', [ $this, 'get_comment_link' ] );
		add_filter( 'wp_title',         [ $this, 'wp_title' ], 10, 1 );

		register_activation_hook( __FILE__,   [ $this, 'activate'] );
		register_deactivation_hook( __FILE__, [ $this, 'deactivate'] );

	function query_vars( $vars ){
		$vars[] = 'comments';

		return $vars;

	# Add a /comments/ page to all post permalinks
	function add_endpoint(){
		add_rewrite_endpoint( 'comments', EP_PERMALINK );

	# Template file for the /comments/ permalink
	function template_redirect( $templates = '' ){
		global $wp_query;

		if( ! isset( $wp_query->query['comments'] ) )
			return $templates;

		$templates = locate_template( 'comments-page.php', false );

		if( ! $templates ){
			$templates = __DIR__ . '/comments-page.php';

		return $templates;

	# Fix comment permalinks
	function get_comment_link( $url ){
		$urlparts = explode( '#', $url );

		return $urlparts[0] . "comments/#" . $urlparts[1];

	# Fix the page title
	function wp_title( $title ){
		global $wp_query;

		if( isset( $wp_query->query['comments'] ) )
			$title = sprintf( self::$page_title_patt, $title );

		return $title;

	function activate(){

	function deactivate(){


Now create a template file. It will be responsible for the output of our page. The file should be named comments-page.php and should be in the same folder as the main plugin file.

Fix code below for your theme.


<article id="post" class="hentry <?= post_class() ?>">

	<h1 class="entry-title">Comments: "<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>"</h1>

	<div class="entry-content">


		wp_list_comments( 'reverse_top_level=false', get_comments([ 'post_id'=> $post->ID ]) );







Now you need to go to the "Permalinks" admin page to reset the rewrite rules.

That's it! A separate page for post comments is ready. Add /comments/ at the end of the URL of the current post and get to the post comments page.