How to Reverse WordPress Comment Order to Show the Latest on Top

Here’s a handy little hack that I found over at iwebsource.net. It basically reverses your comment order to show the latest ones on top, so that you don’t have to scroll all the way to the bottom to find read the most recent comments.

Add this to your theme’s functions.php file:

1
2
3
4
5
6
if (!function_exists('iweb_reverse_comments')) {
    function iweb_reverse_comments($comments) {
        return array_reverse($comments);
    }   
}
add_filter ('comments_array', 'iweb_reverse_comments');

I tested this hack on the WordPress 3.1 and it works as advertised. It’s very useful if you have posts that get pages and pages worth of comments.

Tags

Comments (9)

  1. Or you can just login to your WordPress control panel, go to ‘Setting’>’Discussion’> and under the ‘Other comment settings’ change the drop down from:
    ‘Comments should be displayed with the “older” comments at the top of each page’
    to
    ‘Comments should be displayed with the “newer” comments at the top of each page’

    Simple, no code hacking required :)

  2. Hey there! Anyone know how to change the order of activity thread postings on buddypress – so the thread would appear at the top of the activity when new comments were made on a topic? Right now, the thread gets buried so people can’t find it, even if new comments are added. Thanks!! -John

  3. KJ’s solution for implementing reverse order without code is great. But, I found Sarah’s code based solution has advantages on posts with paginated comments.

    If you use the inbuild WordPress reverse order, and have say 107 comments on a page, with pagination breaks ever 100 comments – then wordpress places the most recent 7 comments on the first page, and the remaining 100 comments on the second page. From a user and SEO perspective, I would rather have the most recent 100 comments on the original blog post, and the oldest 7 comments on the second page. The code based solution paginates the comments ‘correctly’.

  4. Thank you for the code Sarah. It was quick and easy, and best of all it works. I tried two other things first, but couldn’t get the to work before I found your solution. A little good karma is headed your way!

Participate