How to detect a comments page on your WordPress blog

Simply put the following code anywhere on your theme files. If you’re on a comment page, the conditional statement will return true, so any code within brackets will be executed.

$cpage = get_query_var( 'cpage' );
if ( is_singular() && $cpage > 0 ){
    // Your code here
}

This code works on posts, pages, attachments as well as all custom post_types.

Thanks to Daniel Roch for the cool tip!

Leave a Reply

Your email address will not be published. Required fields are marked *