Using WordPress ‘comments_per_page’ PHP filter

The comments_per_page WordPress PHP filter allows you to modify the number of comments displayed per page in the comments list table.

Usage

add_filter('comments_per_page', 'your_custom_function', 10, 2);

function your_custom_function($comments_per_page, $comment_status) {
    // your custom code here
    return $comments_per_page;
}

Parameters

  • $comments_per_page (int): The number of comments to list per page.
  • $comment_status (string): The comment status name. Default is ‘All’.

More information

See WordPress Developer Resources: comments_per_page

Examples

Change comments per page to 15

This example sets the number of comments per page to 15.

add_filter('comments_per_page', 'change_comments_per_page', 10, 2);

function change_comments_per_page($comments_per_page, $comment_status) {
    return 15;
}

Display 10 comments per page for approved comments

This example sets the number of comments per page to 10 for approved comments.

add_filter('comments_per_page', 'approved_comments_per_page', 10, 2);

function approved_comments_per_page($comments_per_page, $comment_status) {
    if ($comment_status == 'approved') {
        return 10;
    }
    return $comments_per_page;
}