While working on the upcoming release of Conversate, our revamped version of the now-famous P2 Theme by Automattic, I rewrote one of the functions they used to display the time on each post, which looked rather ugly on the P2 theme. They used the time and date for each post and with a microblogging platform, it’s typically best to show how long ago something was posted. See example below:
So I thought I would share the function to do this:
|
1 2 3 4 5 6 |
function time_ago( $type = 'post' ) { $d = 'comment' == $type ? 'get_comment_time' : 'get_post_time'; return human_time_diff($d('U'), current_time('timestamp')) . " " . __('ago'); } |
It uses the built-in WordPress function human_time_diff(), which is pretty rad if you ask me. To use it, simply place the function call time_ago() in your single.php or custom comment callback function. Example:
|
1 |
<?php echo time_ago(); ?> |



