How to set/limit number of comments to display per post?

Hook this function to set number of comments to retrieve:

//limit comment
 function limit_comments($query) {
    $query->query_vars['number'] = 5; //set the number of comments
    $query->query_vars['paged'] = 1;

  add_action('pre_get_comments', 'limit_comments');

Where Do I Put This Code?

This code should be placed in the functions.php file of your active theme or a custom functions plugin.

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>