#37: comments_per_page

The comments_per_page filter allows you to define the number of comments to list per page in the comments list table.

It is evaluated in:

comments_per_page accepts 2 arguments:

  1. int $comments_per_page The number of comments to list per page.
  2. string $comment_status The comment status name. Default is ‘all’.

Example:

I don’t know about you, but when I go to clean out spam comments, it’s irritating to have that extra step of upping the comments per page — the default is 20 — just so I can bulk-delete them faster. The following example raises the comments-per-page amount only when you’re in the ‘Spam’ filtered view.

View the code example on Gist.

#7: post_comments_feed_link

The post_comments_feed_link filter allows you to modify the comments feed URL for the current page or post. Since nothing but the URL is provided to the filter, any conditional work will have to be done by you, such as by accessing the $post global.

It is evaluated in get_post_comments_feed_link() in wp-includes/link-template.php.

Example:

Let’s say you (for some reason) will be serving secure content on your comments feed. The following changes the scheme — such as going from http to https — of the post comments feed url.

View the code example on Gist.

#1: pre_comment_author_name

The pre_comment_author_name filter allows you to modify a comment author’s name before the comment is created or updated.

It’s evaluated in:

The value of pre_comment_author_name is also filtered through:

Example:

Let’s say you want to prefix commenters’ names with the word ‘Admin’ if they are administrators on your site. The following example will turn ‘Some Name’ into ‘Admin: Some Name’.

We’ll use the manage_options capability to determine if the commenter is an admin, and if so, filter the name. If they don’t have the capability (aren’t an admin), we’ll return the name unfiltered.