How to: reverse WordPress comments order

Most blogs displays comments from the older to the younger. I have seen many bloggers who asked how to reverse the comment list order, so here’s a recipe.
That’s super easy: We only need the array_reverse() php function.

For those who knows at least a bit of the php programming language, you probably already heard about the array_reverse() function. This function takes an array as argument, and return it reversed.

Just open the comments.php file from your theme. Find the following line:

<?php foreach ($comments as $comment) : ?>

Now, add this line below:

<?php $comments = array_reverse($comments, true); ?>

The code should look like this:

<?php $comments = array_reverse($comments, true); ?>
<?php foreach ($comments as $comment) : ?>
   	// comments loop
<?php endforeach; ?>

That's all. Comments are now displayed in reverse order.

15 Responses

Oct 28 2008 17:06

I did it! Thanks!

Jan 03 2009 23:56

Very nice little trick!

Aug 24 2009 16:27

Brilliant. So simple but it does the job. Thanks.

Aug 24 2009 22:14

Thanks for this quick solution :)

Aug 28 2009 19:00

Definitively it works
all the software shoud be like this, easy and simple…
thx

Oct 23 2009 08:28

Million thanks! Very helpfull!

Apr 13 2010 14:37

Cool! Thanks a lot

Apr 27 2010 11:21

Very strange. I have put your code in the template but it creates an infinite loop so the page keeps on loading and reloading comments.

Apr 27 2010 11:24

My bad, i thought it read to add the line below the first part of the code… works well.

Jun 23 2010 16:27

very good but when i am logged in as admin the order isn’t changed it is only changed when I am not logged in (which is fine for the public) but it looks a bit odd when people are editing the site

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required