Quick Tip: Display Post & Comment Time as “x … ago” Twitter Style

Published on August 13th, 2011

Last Updated on December 12th, 2018

Tags:

Share This Article

If you’d rather show the times on your blog in more user-friendly way, there is a WordPress function called “Human Time Diff” that you can use.

Instead of displaying time in the usual manner of Day Month Year, it will display as “3 days ago” or “2 hours ago” etc – the same style of date that is used on Twitter and Facebook, that people have become used to.

If you’d like to display this for posts, wherever the date is displayed in your theme, replace it with this code :

[php]
<?php echo human_time_diff(get_the_time(‘U’), current_time(‘timestamp’)) . ‘ ago’; ?>
[/php]

If you’d like to do this for comments, the code is :

[php]
<?php echo human_time_diff(get_comment_time(‘U’), current_time(‘timestamp’)) . ‘ ago’; ?>
[/php]

There you have it, a simple way to change up your theme a bit.

Oliver Dale is the founder of Kooc Media, An Internet Company based in Manchester, UK. I founded WPLift in 2010.