How to Sort Comments Reversely in WordPress


By default, WordPress displays comments according to time from the older to the latest. However sometimes we just want to sort comments in the reverse order. Here is how you can, use the array_reverse() php function to achieve the goal.

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

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

Change it to something like this:

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

Once you saved the file, WordPress will displays comments from the older to the latest.

See also  Custom Advertising Banner Layout for Wordpress Site

Leave a Reply

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