I would like to have a separate page for the comments on a post, such that this page: /2011/02/post-name/ just shows the post and then you click a link to view the comments, taking you to a page like this: /2011/02/post-name/comment-page-1/

I will then check the URL to see if "comment-page-x" is in it, and display the page differently if so (remove the post, so people don't have to scroll past that every time, and also style things a bit differently).

This would work, but WordPress redirects comment-page-1 to the post page - I need it to keep comment-page-1 there in the URL.

Is this possible? How can I do it? Thanks!

  • 1
    upvotet the Q. As Mike said: good one :)
    – kaiser
    Feb 11, 2011 at 17:07

1 Answer 1


Great question! WordPress assigns your comment page number to the query var 'cpage' which gets set when your URL has /comment-page-1/ at the end. So your culprit is in the redirect_canonical() function, line 192 of /wp-includes/canoncial.php.

if ( get_query_var('paged') || is_feed() || get_query_var('cpage') ) {

Since the redirect_canonical() function gets set as an action what we can do is to insert our own function to be called instead, have our function set the 'cpage' query var to false, call redirect_canonical(), and then set 'cpage' back to what it was; that will keep WordPress from redirecting on you.

To insert your own function you need to call the two hook 'init' and 'template_redirect' like so being sure to set the 'init' hook to be called after the do_action() inside WordPress core that adds redirect_canonical():

add_action('init','yoursite_init',11); //11=lower priority
function yoursite_init() {

function yoursite_redirect_canonical($requested_url=null, $do_redirect=true) {
  $cpage = get_query_var('cpage');
  redirect_canonical($requested_url, $do_redirect);

Then of course you need to do something with your 'cpage'. You can either check for the value returned by get_query_var('cpage') or you can add another hook to allow you to create a comment-specific template which is what I did. It will add look for a theme template file with the same as it would normally load but with [comments].php at the end of the name instead of .php, i.e. single[comments].php. Note that I set priority for this filter to be 11; you may need to set to an even larger number if a plugin you use adds itself after your hook:

function yoursite_single_template($template) {
  if (get_query_var('cpage'))
    $template = str_replace('.php','[comments].php',$template);
  return $template;

And here's the proof that it all works!

Screenshot of Custom WordPress Page Template for Comments
(source: mikeschinkel.com)

  • Short.... wow! Too bad we can't do a +10 over here...
    – kaiser
    Feb 11, 2011 at 14:35
  • Thanks for the detailed response, but a question - where can I put this code? I've tried in functions.php but not having much luck. Assuming I'm using twentyten theme, where in the file do I add the code?
    – Shaun
    Feb 11, 2011 at 14:41
  • @Shaun - Figures. :) The one time I didn't add the following text to my answer I get called for it: "You can add the following code to your theme's functions.php file or in a .php file of a plugin you might be writing." But you say that is not working? What exactly is it not doing? Have you put echo "Test"; exit; statements in each of the functions to make sure the hooks are firing? Do you have plugins that may be conflicting? Did you try changing 11 in two places to 100? Did you include all the code? Did you create a theme template file called single[comments].php? Feb 11, 2011 at 15:08
  • @MikeSchinkel Brilliant, thanks. I did not create the single[comments].php!
    – Shaun
    Feb 11, 2011 at 17:14
  • @Shaun - Glad I could help! Feb 11, 2011 at 18:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.