Site icon CodeRevolution Knowledge Base

How to detect a comments page on your WordPress blog – CodeRevolution

On WordPress dashboard, there’s an option to divide comments lists in sub pages. Unfortunately, there’s no built-in conditional tag to know if you’re currently on a comment page. So let’s built one!

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!

Exit mobile version