Sort comment in reverse order – WordPress

Author posted by Jitendra on Posted on under category Categories Tech Tips, Web Technology and tagged as Tags with Leave a comment on Sort comment in reverse order – WordPress

PHP code to sort the comment in WordPress blog in reverse order

In many cases the blogger may want to sort the comment of there WordPress blog by latest comment at top, like me.

Instead of installing any plugin, i have done following code changes in “comments.php“.

Somewhere in “comments.php“, you will find below line of code –

foreach ($comments as $comment) :

Add following code just above the for loop

$comments = array_reverse($comments);

so, the final code will become

<?php
	/*Start By Jitendra*/
	$comments = array_reverse($comments);
	/*End By Jitendra*/
	foreach ($comments as $comment) :
?>

I hope, this little trick will be very useful for few WordPress bloggers.

Related posts