Display time ago(twitter style)

If you want to show how long ago something was posted(comments, post etc.), you can use WordPress human_time_diff-function. This will display something like “5 days ago“.

Code Snippet:

<?php 
# For posts & pages #
echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago';
# For comments #
echo human_time_diff(get_comment_time('U'), current_time('timestamp')) . ' ago'; 

// Change to the date after a certain time
$time_difference = current_time('timestamp') - get_the_time('U');
if($time_difference < 86400) {
	//here goes the code from one of the sample above
} else {
	the_time();
};
?>

Posted in Posts, Comments