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.

2 Responses

Aug 09 2011 16:00

Many thanks – This is just what I was looking for to reverse the order of comments. The built-in WordPress setting didn’t work for me.

Jan 25 2012 07:57

Thanks so much for this. I was able to use your code on another WP issue and it also resolved it! I wish more programmers would share little gold nuggets like this with us non-programming types.

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox